Chapter 16. Layers
A UIView has a partner called its layer, a CALayer. A UIView does not actually draw itself onto the screen; it draws itself into its layer, and it is the layer that appears on the screen. As already mentioned in the previous two chapters, a view is not redrawn frequently; instead, its drawing is cached, and the cached version of the drawing is used where possible. The cached version is, in fact, the layer.
This might seem like a mere implementation detail, but layers are important and interesting. To understand layers is to understand views more deeply; layers extend the power of views. In particular:
- Layers have properties that affect drawing.
- Layers have drawing-related properties beyond those of a UIView. Because a layer is the recipient and presenter of a view’s drawing, you can modify how a view is drawn on the screen by accessing the layer’s properties. In other words, by reaching down to the level of its layer, you can make a view do things you can’t do through UIView methods alone.
- Layers can be combined within a single view.
- A UIView’s partner layer can contain additional layers. Since the purpose of layers is to draw, portraying visible material on the screen, this allows a UIView’s drawing to be composited of multiple distinct pieces. This can make drawing easier, with the constituents of a drawing being treated as objects.
- Layers are the basis of animation.
- Animation allows you to add clarity, emphasis, and just plain coolness to your interface. ...