Core Animation & CATransaction Protip

My impression so far is that the documentation for Core Animation is pretty scant.  CATransaction allows you to animate a bunch of objects, and the system will treat them as one atomic operation.  The format is similar to the old-style animation for UIViews:


[CATransaction begin];

// animate some stuff

[CATransaction commit];

The transaction also allows you to specify a block that will fire after completion:


[CATransaction begin];

[CATransaction setCompletionBlock:(void) { /*code*/ }];

// animate some stuff

[CATransaction commit];

It’s worth noting that if you specify the completion block after the animations the completion block will fire immediately, whereas if you place the completion block before the animations, it will fire as you expect.

Posted on February 24, 2011, in Code and tagged , , . Bookmark the permalink. 3 Comments.

  1. Thompson Usiyan

    You are wonderful. Thank you.

    “It’s worth noting that if you specify the completion block after the animations the completion block will fire immediately, whereas if you place the completion block before the animations, it will fire as you expect.”

    That had me scratching my head for a few hours. NEVER thought to move the block to before the animations.

  2. Thanks for that man, you really saved me a couple of hours

Leave a comment