Graphics Reference
In-Depth Information
LISTING 5-7
Continued
[CATransaction begin];
[CATransaction setValue:[NSNumber numberWithFloat:5.0f]
forKey:kCATransactionAnimationDuration];
[layer setPosition:CGPointMake(x, y)];
scale = CATransform3DMakeScale (0.1f, 0.1f, 1.0f);
rotate = CATransform3DMakeRotation (1.57f, 0.0f, 0.0f, 1.0f);
[layer setTransform:rotate];
[layer setTransform:scale];
[CATransaction commit];
}
However, when this code is run, the layer moves and rotates, but it does not scale. This is
because calling -setTransform: is only a property, and the last value we set into it wins
and discards any previous values that have been set. Although this can be useful in some
situations—as both the removal of the old transform and the setting of the new transform
are both animated—it is not the effect we look for in this example.
Because the transforms override each other, the transforms need to be combined before
applying them to the layer. This is accomplished with the CATransform3DConcat method,
which takes two CATransform3D references and returns a single combined CATransform3D ,
as shown in Listing 5-8.
LISTING 5-8
-action:
- ( IBAction )action:( id )sender;
{
NSRect frame = [[[ self window] contentView] frame];
float x = frame. origin . x + frame. size . width - 30;
float y = frame. origin . y + frame. size . height - 30;
CATransform3D rotate;
CATransform3D scale;
CATransform3D combine;
[CATransaction begin];
[CATransaction setValue:[NSNumber numberWithFloat:5.0f]
forKey:kCATransactionAnimationDuration];
[layer setPosition:CGPointMake(x, y)];
scale = CATransform3DMakeScale (0.1f, 0.1f, 1.0f);
rotate = CATransform3DMakeRotation (1.57f, 0.0f, 0.0f, 1.0f);
combine = CATransform3DConcat (rotate, scale);
 
Search WWH ::




Custom Search