Animation Transactions and Grouping
When you start an animation (either by adding it to a layer or calling [object animator]), that animation will begin immediately. If you want several animations to begin at the same time, then you need to group them in a transaction. Just like animations discussed earlier, there are two types of transactions—implicit and explicit.
Implicit transactions are the easiest to use. To use them, there is no additional code to write and only a very simple rule to follow. If there is no current active CATransaction, then when you first call an animation a transaction will be created for you. Likewise, the transaction will automatically be committed at the beginning of the next iteration of the run loop. If you are manipulating animations on a thread that does not have a run loop, then you must use explicit transactions.
Explicit transactions are not very complex in themselves. While they do require additional code, that code is very straight-forward. Here's how to begin an explicit transaction:
And when you are ready to commit the transaction, you need:
You can also flush a transaction if you need to abort an animation:
In addition to beginning and ending a transaction, you can also define the duration of each animation in the transaction with one call to the transaction itself:
[CATransaction setValue:[NSNumber numberWithFloat:10.0f] forKey:kCATransactionAnimationDuration];