Graphics Reference
In-Depth Information
Unlike
bounds
and
frame
,
contentsRect
is not measured in points; it uses
unit
coordinates.
Unit coordinates are specified in the range 0 to 1, and are
relative
values (as
opposed to
absolute
values like points and pixels). In this case, they are relative to the
backing image's dimensions. The following coordinate types are used in iOS:
▪
Points
—The most commonly used coordinate type on iOS and Mac OS. Points are
virtual
pixels, also known as
logical
pixels. On standard-definition devices, 1 point
equates to 1 pixel, but on Retina devices, a point equates to 2×2 physical pixels. iOS
uses points for all screen coordinate measurements so that layouts work seamlessly on
both Retina and non-Retina devices.
▪
Pixels
—Physical pixel coordinates are not used for screen layout, but they are often
still relevant when working with images.
UIImage
is screen-resolution aware, and
specifies its size in points, but some lower-level image representations such as
CGImage
use pixel dimensions, so you should keep in mind that their stated size will
not match their display size on a Retina device.
▪
Unit
—Unit coordinates are a convenient way to specify measurements that are
relative to the size of an image or a layer's bounds, and so do not need to be adjusted
if that size changes. Unit coordinates are used a lot in OpenGL for things like texture
coordinates, and they are also used frequently in Core Animation.
The default
contentsRect
is {0, 0, 1, 1}, which means that the entire backing image
is visible by default. If we specify a smaller rectangle, the image will be clipped (see
Figure 2.6).
Figure 2.6
A custom
contentsRect
(left) and the displayed contents (right)