Graphics Reference
In-Depth Information
Parallel Hierarchies
Every
UIView
has a
layer
property that is an instance of
CALayer
. This is known as
the
backing layer.
The view is responsible for creating and managing this layer and for
ensuring that when subviews are added or removed from the view hierarchy that their
corresponding backing layers are connected up in parallel within the layer tree (see
Figure 1.2).
Figure 1.2
The structure of the layer tree (left) mirrors that of the view hierarchy (right)
It is actually these backing layers that are responsible for the display and animation of
everything you see onscreen.
UIView
is simply a wrapper, providing iOS-specific
functionality such as touch handling and high-level interfaces for some of Core
Animation's low-level functionality.
Why does iOS have these two parallel hierarchies based on
UIView
and
CALayer
? Why
not a single hierarchy that handles everything? The reason is to separate responsibilities,
and so avoid duplicating code. Events and user interaction work quite differently on iOS
than they do on Mac OS; a user interface based on multiple concurrent finger touches
(
multitouch
) is a fundamentally different paradigm to a mouse and keyboard, which is why
iOS has UIKit and
UIView
and Mac OS has AppKit and
NSView
. They are functionally
similar, but differ significantly in the implementation.