Graphics Reference
In-Depth Information
For example, if we specified a 10-second animation with five keyframes, the time given to
each keyframe is 2.5 seconds:
10 / (5 - 1) = 2.5
You can gain further control of your animation timing with the keyTimes field, which you
can use to specify a percentage for each keyframe from the animation's total duration.
With five keyframes specified in an animation, each keyTime takes up 25 percent of the
total time. If we were to explicitly set up our animation to use the keyTimes field in a way
that would essentially do the same as the default, the code would look like Listing 4-3.
LISTING 4-3
Explicitly Setting Key Times to Mimic the Default
[animation setCalculationMode : kCAAnimationLinear ];
[animation setKeyTimes :
[ NSArray arrayWithObjects :
[ NSNumber numberWithFloat :0.0],
[ NSNumber numberWithFloat :0.25],
[ NSNumber numberWithFloat :0.50],
[ NSNumber numberWithFloat :0.75],
[ NSNumber numberWithFloat :1.0], nil ]];
You might have noticed that we specified five values in Listing 4-3, which might not
seem to match our default formula. However, when you realize that the first value ( 0.0 ) is
simply a starting value, it becomes clear that we are only specifying four destination
times, which matches the formula discussed earlier.
The animation in Listing 4-3 is identical to what you see if you didn't specify key times at
all; this simply shows you how to specify the key times should you need to do that in
your animation. You can alter these values to lengthen or shorten the amount of time
spent between the keyframes. Just remember that each subsequent value must be greater
than the previous and must not exceed 1.0 . The duration and number of keyframes
provide enough information for Core Animation to interpolate the values in the exact
same way by simply dividing the duration by the number of keyframes minus one.
The key times are used according to the calculationMode field, as shown in Listing 4-3.
When specified as paced ( kCAAnimationPaced ), the key times are ignored. This is the same
as if you didn't specify key times at all. When specified as linear ( kCAAnimationLinear )
the times in between keyframes are interpolated, which means that you see every step of
the animation between keyframes. This is the process of tweening that we discussed at
the beginning of this chapter. When specified as discrete ( kCAAnimationDiscrete ), the
keyframes are the only frames displayed, with no interpolation between frames. If you
moved a layer to random points on a window, for instance, you would not see the layer
move to each point. Instead, you would see the layer jump to each point when the time
for that keyframe was reached.
 
Search WWH ::




Custom Search