Implicit Layer Animation

If a layer is not a view’s underlying layer, animating it can be as simple as setting a property. A change in what the documentation calls an animatable property is automatically interpreted as a request to animate that change. In other words, animation of layer property changes is the default! Multiple property changes are considered part of the same animation. This mechanism is called implicit animation.


You cannot use implicit animation on the underlying layer of a UIView. You can animate a UIView’s underlying layer directly, but you must use explicit animation (discussed in the upcoming section on Core Animation).

For example, in Chapter 16 we constructed a compass out of layers. The compass itself is a CompassView that does no drawing of its own; its underlying layer is a CompassLayer that also does no drawing, serving only as a superlayer for the layers that constitute the drawing. None of the layers that constitute the actual drawing is the underlying layer of a view, so a property change to any of them is animated automatically.

So, presume that we have a reference to the arrow layer, a property theArrow of the CompassLayer, and also a reference to the CompassView, a property compass of the app delegate, which is self. If we rotate the arrow by changing its transform property, that rotation is animated:

CompassLayer* c = (CompassLayer*)self.compass.layer; // the next line is an implicit animation c.theArrow.transform = CATransform3DRotate(c.theArrow.transform, ...

Get Programming iOS 4 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.