Graphics Reference
In-Depth Information
FIGURE 5-2
Center Anchor Point
LISTING 5-5
Updated Anchor Point
CGRect
workFrame = [layer
bounds
];
workFrame.
origin
.
x
= workFrame.
size
.
width
/ 4;
workFrame.
origin
.
y
= workFrame.
size
.
height
/ 4;
workFrame.
size
.
width
/= 2;
workFrame.
size
.
height
/= 2;
[workLayer setAnchorPoint:CGPointMake(0, 0)];
[
workLayer setFrame
:workFrame];
[layer
addSublayer
:
workLayer
];
In Listing 5-5, we added the line
[workLayer setAnchorPoint:CGPointMake(0, 0)];
. This
relocates the anchor point to the lower-left corner of the layer. When the scale transform
is run, you can see that the layer appears to shrink to the lower-left corner, as shown in
Figure 5-3.
By combining transforms along with anchor point manipulation, you can produce some
interesting results. For example, we could cause the layer to rotate along the
z
-axis with a
single corner remaining stationary. By moving the anchor point to the desired corner and
rotating only along the
z
-axis, the layer appears to rotate as if it were attached to some
object. If we then placed another layer that matches that same corner, it would be a very
convincing effect.