Blog Archives

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.

Advertisements