Graphics Reference
In-Depth Information
Layer Resizing
Animating a layer's frame is a bit different from doing the same in windows and views.
There is no animator proxy available in a CALayer object, but rather animation is always
used when you make an explicit change to a property. In fact, if you don't want anima-
tion used, you have to explicitly turn animation off. Listing 3-5 demonstrates how to
do this.
LISTING 3-5
Explicitly Disabling Layer Animation
[ CATransaction begin ]
[ CATransaction setValue :[ NSNumber numberWithBool : YES ]
forKey : kCATransactionDisableActions ]
[layer setBounds :bounds];
[ CATransaction commit ];
NOTE
Notes on Disabling Animations
Alternatively, you can disable animations in a layer based on a keypath by using the delegate
method:
- (id<CAAction>)actionForLayer:(CALayer *)layer forKey :(NSString *)key
It returns an object that implements the CAAction protocol. It might also return NSNull ,
which in effect disables the animation for the key specified in the key parameter of the dele-
gate method. When you implement this delegate method, simply check to see if the layer
passed in is the one you are working with, and then check to see if the key field is the same
as the keypath for which you want to disable animation. If it is, return NSNull .
The CATransaction class is the Core Animation analogue to AppKit's NSAnimationContext
object we used in Listing 3-2 and 3-4 for windows and views. Just like
NSAnimationContext , CATransaction enables us to set the animation duration. Listing 3-6
demonstrates how to do this.
LISTING 3-6
Setting Animation Duration in a Layer
[ CATransaction begin ]
[ CATransaction setValue :[ NSNumber numberWithFloat : 5.0f]
forKey : kCATransactionAnimationDuration ]
[layer setBounds :bounds];
[ CATransaction commit ];
 
Search WWH ::




Custom Search