An Example Basic Animation
CABasicAnimation *theAnimation; // create the animation object, specifying the position property as the key path // the key path is relative to the target animation object (in this case a CALayer) theAnimation=[CABasicAnimation animationWithKeyPath:@"position"]; // set the fromValue and toValue to the appropriate points theAnimation.fromValue=[NSValue valueWithPoint:NSMakePoint(74.0,74.0)]; theAnimation.toValue=[NSValue valueWithPoint:NSMakePoint(566.0,406.0)]; // set the duration to 3.0 seconds theAnimation.duration=3.0; // set a custom timing function theAnimation.timingFunction=[CAMediaTimingFunction functionWithControlPoints:0.25f :0.1f :0.25f :1.0f];
Providing Keyframe Values
// create a CGPath that implements two arcs (a bounce) CGMutablePathRef thePath = CGPathCreateMutable(); CGPathMoveToPoint(thePath,NULL,74.0,74.0); CGPathAddCurveToPoint(thePath,NULL,74.0,500.0, 320.0,500.0, 320.0,74.0); CGPathAddCurveToPoint(thePath,NULL,320.0,500.0, 566.0,500.0, 566.0,74.0); CAKeyframeAnimation * theAnimation; // create the animation object, specifying the position property as the key path // the key path is relative to the target animation object (in this case a CALayer) theAnimation=[CAKeyframeAnimation animationWithKeyPath:@"position"]; theAnimation.path=thePath; // set the duration to 5.0 seconds theAnimation.duration=5.0; // release the path CFRelease(thePath);