Graphics Reference
In-Depth Information
3
Let no one unversed in geometry enter here.
Sign above the entrance to Plato's Academy
Chapter 2, “The Backing Image,” introduced the layer-backing image and the properties
used to control its position and scaling within the layer bounds. In this chapter, we look at
how the layer itself is positioned and sized with respect to its superlayer and siblings. We
also explore how to manage your layer's geometry and how it is affected by autoresizing
and autolayout.
UIView
has three primary layout properties:
frame
,
bounds
, and
center
.
CALayer
has equivalents called
frame
,
bounds
, and
position
. Why they used “position” for
layers and “center” for views will become clear, but they both represent the same value.
The
frame
represents the
outer
coordinates of the layer (that is, the space it occupies
within its superlayer), the
bounds
property represents the
inner
coordinates (with {0, 0}
typically equating to the top-left corner of the layer, although this is not always the case),
and the
center
and
position
both represent the location of the
anchorPoint
relative to the superlayer. The
anchorPoint
property is explained later, but for now just
think of it as the center of the layer. Figure 3.1 shows how these properties relate to one
another.
The view's
frame
,
bounds
, and
center
properties are actually just
accessors
(setter
and getter methods) for the underlying layer equivalents. When you manipulate the view
frame
, you are really changing the
frame
of the underlying
CALayer
. You cannot
change the view's
frame
independently of its layer.