Graphics Reference
In-Depth Information
LISTING 5-4
-rotate3DTransform:
- ( IBAction )rotate3DTransform:( id )sender;
{
NSValue *value = nil ;
CABasicAnimation *animation = nil ;
CATransform3D transform;
[[ self workLayer ] removeAllAnimations ];
animation = [CABasicAnimation animationWithKeyPath: @”transform” ];
transform = CATransform3DMakeRotation (1.57f, 1.0f, 1.0f, 0.0f);
value = [NSValue valueWithCATransform3D:transform];
[animation setToValue :value];
transform = CATransform3DMakeRotation (0.0f, 1.0f, 1.0f, 0.0f);
value = [NSValue valueWithCATransform3D:transform];
[animation setFromValue :value];
[animation setAutoreverses : YES ];
[animation setDuration :1.0f];
[animation setRepeatCount :100];
[workLayer addAnimation:animation forKey: kScaleKey ];
}
Listing 5-4 is nearly identical to Listing 5-3 except for the values passed into the
CATransform3DMakeRotation method. This example sets both the x - and y -axes to 1.0 ,
which produces a rotation on both axes and gives the illusion that the layer is flipping
diagonally.
Because we rotate the layer by 90 degrees and auto-reversing, this example appears to be
flipping all the way around on two axes. This would be useful when you have a two-sided
layer (such as a coin or a poker chip) and want to flip between its sides.
Anchor Points
As previously mentioned in the discussion about layers, anchor points become extremely
important when dealing with transforms. When you apply a transform to a layer, the
transform uses the anchor point to determine where to rotate, scale, and so on.
With the examples so far, the scale transform (shown earlier in Listing 5-2) causes the
layer to appear to shrink into the middle of the window, as shown in Figure 5-2. This is
because the default position of the anchor point of any layer is the center.
However, if we alter - applicationDidFinishLaunching: and move the anchor point to
the lower-left corner of the layer, as shown in Listing 5-5, we get a dramatically different
effect.
 
 
Search WWH ::




Custom Search