Graphics Programs Reference
In-Depth Information
aTimingFunction . By default, the timing function is linear - the values are interpol-
ated linearly. Changing the timing function changes how these animations are interpol-
ated. It doesn't change the duration or the keyframes.
In spinTimeLabel , change the timing function to “ease” in and out of the animation.
[spin setDuration:1.0];
// Set the timing function
CAMediaTimingFunction *tf = [CAMediaTimingFunction
functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
[spin setTimingFunction:tf];
[[timeLabel layer] addAnimation:spin
forKey:@"spinAnimation"];
}
Build and run the application and see how the animation changes.
There are four timing functions, you have seen linear and kCAMediaTimingFunc-
tionEaseInEaseOut . The other two are kCAMediaTimingFunctionEaseIn
(accelerates gradually, stops suddenly) and kCAMediaTimingFunctionEaseOut
(accelerates suddenly, stops slowly). You can also create your own timing functions with
CAMediaTimingFunction . See the doc for details.
Animation completion
Sometimes you want to know when an animation is finished. For instance, you might
want to chain animations or update another object when an animation completes. How can
you know when an animation is complete? Every animation object can have a delegate,
and the animation object sends the message animationDidStop:finished: to its
delegate when an animation stops.
Edit TimeViewController.m so that it logs a message to the console whenever an
animation stops.
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
NSLog(@"%@ finished: %d", anim, flag);
}
- (void)spinTimeLabel
{
// Create a basic animation
CABasicAnimation *spin =
[CABasicAnimation animationWithKeyPath:@"transform.rotation"];
[spin setDelegate:self];
// fromValue is implied
Search WWH ::




Custom Search