Graphics Reference
In-Depth Information
the bottom -left corner. Core Animation can support either of these conventions by virtue of
the geometryFlipped property. This is a BOOL value that determines whether the
geometry of a layer is vertically flipped with respect to its superlayer. Setting this property to
YES for a layer on iOS means that its sublayers will be flipped vertically and will be
positioned relative to the bottom of its bounds rather than the top as normal (as will all of
their sublayers, and so on, unless they also have YES for their geometryFlipped
property).
The Z Axis
Unlike UIView , which is strictly two-dimensional, CALayer exists in three-dimensional
space. In addition to the position and anchorPoint properties that we have already
discussed, CALayer has two additional properties, zPosition and anchorPointZ ,
both of which are floating-point values describing the layer's position on the Z axis.
Note that there is no depth property to complement the bounds width and height. Layers
are fundamentally flat objects. You can think of them as being a bit like stiff sheets of paper
that are individually two-dimensional but that can be glued together to form hollow,
origami-like 3D structures.
The zPosition property is not particularly useful in most cases. In Chapter 5, we explore
CATransform3D , and you learn how to move and rotate layers in three dimensions. But
without using transforms, the only practical use you are likely to find for the zPosition
property is to change the display order of your layers.
Normally, layers are drawn according to the order in which they appear in the sublayers
array of their superlayer. This is known as the painter's algorithm because—like a painter
painting a wall—layers that are painted later will obscure the layers that were painted
earlier. But by increasing the zPosition of a layer, you can move it forward toward the
camera so that it is physically in front of all other layers (or at least, in front of any layer
with a lower zPosition value).
The “camera” in this case is just how we refer to the user's viewpoint. It has nothing to do
with the camera built in to the back of the iPhone (although it does point in the same
direction, coincidentally).
Figure 3.8 shows a pair of views arranged in Interface Builder. As you can see, the green
view—which appears first in the view hierarchy—is drawn underneath the red view, which
appears later in the list.
Search WWH ::




Custom Search