Graphics Reference
In-Depth Information
//set up animation parameters
NSValue * fromValue = [ NSValue valueWithCGPoint :CGPointMake( 150 , 32 )];
NSValue *toValue = [NSValue valueWithCGPoint:CGPointMake( 150 , 268 )];
CFTimeInterval duration = 1.0 ;
//generate keyframes
NSInteger numFrames = duration * 60 ;
NSMutableArray *frames = [NSMutableArray array];
for ( int i = 0 ; i < numFrames; i++)
{
float time = 1 /( float )numFrames * i;
//apply easing
time = bounceEaseOut(time);
//add keyframe
[ frames addObject:[ self interpolateFromValue :fromValue
toValue :toValue
time:time]];
}
//create keyframe animation
CAKeyframeAnimation * animation = [CAKeyframeAnimation animation];
animation. keyPath = @"position" ;
animation. duration = 1.0 ;
animation. delegate = self ;
animation.values = frames;
//apply animation
[ self .ballView.layer addAnimation:animation forKey: nil ];
}
Summary
In this chapter, you learned about easing, and the CAMediaTimingFunction class, which
allows us to create custom easing functions to fine-tune our animations. You also learned
how to use CAKeyframeAnimation to bypass the limitations of CAMediaTimingFunction
and create your own completely bespoke easing functions.
In the next chapter, we look at timer-based animation—an alternative approach to
animation that gives us more control and makes it possible to manipulate animations on-
the-fly.
 
Search WWH ::




Custom Search