Graphics Programs Reference
In-Depth Information
The difference between CABasicAnimation and CAKeyframeAnimation is that a
basic animation only interpolates two values while a keyframe animation can interpolate
as many values as you give it ( Figure 23.4 ). These values are put into an NSArray in the
order in which they are to occur. This array is then set as the values property of a
CAKeyframeAnimation instance.
CAKeyframeAnimation *mover = [CAKeyframeAnimation anima-
tionWithKeyPath:@"position"];
NSArray *vals = [NSMutableArray array];
[vals addObject:[NSValue valueWithCGPoint:CGPointMake(0.0, 100.0)]];
[vals addObject:[NSValue valueWithCGPoint:CGPointMake(100.0, 100.0)]];
[mover setValues:vals];
[mover setDuration:1.0];
Each value in the values property is called a keyframe . Keyframes are the values that
the animation will interpolate; the animation will take the property it is animating through
each of these keyframes over its duration. A basic animation is really a keyframe anima-
tion that is limited to two keyframes. (In addition to allowing more than two keyframes,
CAKeyframeAnimation adds the ability to change the timing of each of the key-
frames, but that's more advanced than what we want to talk about right now.)
There are two more CAAnimation subclasses, but they are used less often. A CAAnim-
ationGroup instance holds an array of animation objects. When an animation group is
added to a layer, the animations run concurrently.
CABasicAnimation *mover = [CABasicAnimation animationWithKeyPath:@"position"];
[mover setDuration:1.0];
Search WWH ::




Custom Search