Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does [UIView beginAnimations] work?

I was wondering how animations work in Cocoa Touch. For example:

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];

view1.alpha = 1.0;
view2.frame.origin.x += 100;

[UIView commitAnimations];

How does UIView tracks the changes to the properties of the two views?

I suspect that KVO is used, but does it really observe the changes to every views between the beginAnimations and commitAnimations calls?

Any insight would be appreciated!

like image 855
Martin Cote Avatar asked Aug 26 '09 20:08

Martin Cote


1 Answers

A simplified explanation:

All animations for all views are handled on a single stack, beginAnimations:context: will push a new active CAAnimationGroup on the stack, and commitAnimations will pop the current active animation group.

If there is an active animation group on the stack, then all setters for animatable properties will create CAAnimation subclass instances to handle that property and add then to the active animation group.

When the last animation is popped, it is replayed.

like image 80
PeyloW Avatar answered Nov 17 '22 02:11

PeyloW