Graphics Reference
In-Depth Information
Figure 1.1
A typical iOS screen (left) and the view hierarchy that forms it (right)
In iOS, views all inherit from a common base class,
UIView
.
UIView
handles touch
events and supports
Core Graphics
-based drawing, affine transforms (such as rotation or
scaling), and simple animations such as sliding and fading.
What you may not realize is that
UIView
does not deal with most of these tasks itself.
Rendering, layout, and animation are all managed by a Core Animation class called
CALayer
.
CALayer
The
CALayer
class is conceptually very similar to
UIView
. Layers, like views, are
rectangular objects that can be arranged into a hierarchical tree. Like views, they can
contain content (such as an image, text, or a background color) and manage the position of
their children (
sublayers
). They have methods and properties for performing animations
and transforms. The only major feature of
UIView
that isn't handled by
CALayer
is user
interaction.
CALayer
is not aware of the
responder chain
(the mechanism that iOS uses to propagate
touch events through the view hierarchy) and so cannot respond to events, although it does
provide methods to help determine whether a particular touch point is within the bounds of
a layer (more on this in Chapter 3, “Layer Geometry”).