Graphics Reference
In-Depth Information
possible to add layers in this way, more often than not you will simply work with views and
their backing layers and won't need to manually create additional hosted layers.
On Mac OS, prior to version 10.8, a significant performance penalty was involved in using
hierarchies of layer-backed views instead of standalone CALayer trees hosted inside a
single view. But the lightweight UIView class in iOS barely has any negative impact on
performance when working with layers. (In Mac OS 10.8, the performance of NSView is
greatly improved, as well.)
The benefit of using a layer-backed view instead of a hosted CALayer is that while you
still get access to all the low-level CALayer features, you don't lose out on the high-level
APIs (such as autoresizing, autolayout, and event handling) provided by the UIView class.
You might still want to use a hosted CALayer instead of a layer-backed UIView in a real-
world application for a few reasons, however:
You might be writing cross-platform code that will also need to work on a Mac.
You might be working with multiple CALayer subclasses (see Chapter 6,
“Specialized Layers”) and have no desire to create new UIView subclasses to host
them all.
You might be doing such performance-critical work that even the negligible overhead
of maintaining the extra UIView object makes a measurable difference (although in
that case, you'll probably want to use something like OpenGL for your drawing
anyway).
But these cases are rare, and in general, layer-backed views are a lot easier to work with
than hosted layers.
Summary
This chapter explored the layer tree, a hierarchy of CALayer objects that exists in parallel
beneath the UIView hierarchy that forms the iOS interface. We also created our own
CALayer and added it to the layer tree as an experiment.
In Chapter 2, “The Backing Image,” we look at the CALayer backing image and at the
properties that Core Animation provides for manipulating how it is displayed.
 
Search WWH ::




Custom Search