Graphics Reference
In-Depth Information
Figure 3.7 The clock face, with correctly aligned hands
Coordinate Systems
Layers, like views, are positioned hierarchically, with each placed relative to its parent in
the layer tree. The position of a layer is relative to the bounds of its superlayer. If the
superlayer moves, so do all of its sublayers.
This is convenient when positioning layers because it allows you to move a subtree of
several layers as a single unit just by moving the root layer. But sometimes you need to
know the absolute position of a layer or (more commonly) its position relative to a layer
other than its immediate parent.
CALayer provides some utility methods for converting between different layers'
coordinate systems:
- ( CGPoint )convertPoint:( CGPoint )point fromLayer:( CALayer *)layer;
- ( CGPoint )convertPoint:( CGPoint )point toLayer:( CALayer *)layer;
- ( CGRect )convertRect:( CGRect )rect fromLayer:( CALayer *)layer;
- ( CGRect )convertRect:( CGRect )rect toLayer:( CALayer *)layer;
These methods enable you to take either a point or rectangle defined in the coordinate system
of one layer and convert it to the coordinate system of another.
Flipped Geometry
Conventionally, on iOS the position of a layer is specified relative to the top-left corner
of its superlayer's bounds. On Mac OS, the convention is that the position is relative to
 
Search WWH ::




Custom Search