Graphics Reference
In-Depth Information
Listing 3-10
Overriding the Default Duration for Implicit Animation
[CATransaction begin ];
[ CATransaction setValue :[ NSNumber numberWithFloat :5.0]
forKey : kCATransactionAnimationDuration ];
[layer setPosition :endPoint];
[ CATransaction commit ];
However, when you run this code, you see that although it animates the position over
a five second duration, it also applies the default media timing function that is
kCAMediaTimingFunctionEaseInEaseOut . This function causes the animation to start
slowly and then speed up only to slow down again as it approaches its destination. This
functionality is fine if that is the media timing function you want, but if you want it to
be linear ( kCAMediaTimingFunctionLinear ), for example, you need to consider another
way. And there is no apparent way to set the default media timing function for implicit
animations.
This means that if you want to use any other timing function than the default, you have
to use explicit animation, as shown in Listing 3-9.
Visual Stickiness
Another approach we might take is to set several properties in our animation object that
cause the animation to be sticky when it finishes. In other words, the layer will appear to
be at the destination value. The stickiness in this scenario, however, is visual only, which
is to say that the underlying value of the layer property, position continues to be the
value the position was when the animation started. This is a fine approach if you don't
need the internal value to be updated. Listing 3-11 shows how to implement this method,
making the layer stick at the end of its duration.
LISTING 3-11
Making the Layer Position Sticky
CABasicAnimation *animation = [ CABasicAnimation
animationWithKeyPath : @”position” ];
[animation setToValue:[ NSValue valueWithPoint:endPoint]];
[animation setDuration :5.0];
[animation setFillMode : kCAFillModeForwards ];
[animation setRemovedOnCompletion : NO ];
[layer addAnimation :animation forKey :@”position”];
 
Search WWH ::




Custom Search