Graphics Reference
In-Depth Information
//move the green view zPosition nearer to the camera
self .greenView. layer . zPosition = 1.0f ;
}
@end
Figure 3.9 The green view is drawn in front of the red view.
Hit Testing
Chapter 1, “The Layer Tree,” stated that it's usually preferable to use views with backing
layers rather than constructing standalone layer hierarchies. One of the reasons for this is
because of the extra complexity of handling touch events when using layers.
CALayer does not have any knowledge of the responder chain, so it cannot deal with
touch events or gestures directly. It does have a couple of methods to help you to
implement touch handling yourself, however: -containsPoint: and -hitTest: .
The -containsPoint: method accepts a CGPoint in the layer's own coordinate
system, and returns YES if the point lies inside the layer's frame . Listing 3.4 shows the
code for an adapted version of the project from Chapter 1 that uses the
-containsPoint: method to determine whether either the white or blue layers are
being touched (see Figure 3.10). This is made somewhat awkward by the need to convert
the touch position to each layer's coordinate system in turn.
 
Search WWH ::




Custom Search