Learning notes of Core Animation for Mac OS X and the iPhone
1. The Simplest animation (CABasicAnimation)
Without animation: [theView setFrame:newFrame];
With animation: [[theView animator] setFrame:newFrame];
[theView animator] is the Animator Proxy which is simply finding an animation and then invoking it. The default animation is CABasicAnimation.
2. CAKeyframeAnimation
With CAfeyFrameAnimation, you can define a series of key frames. CoreAnimation system will create animation based on these key frames. For example, we want to create an animation of moving an image to point A, and then B. We only need to create the key frames of A and B. CAKeyframeAnimation could be understood as a series of CABasicAnimation.
// Create the path
NSRect frame = [theView frame];
CGMutablePathRef thePath = CGPathCreateMutable();
CGPathMoveToPoint(thePath, NULL, NSMinX(frame), NSMinY(frame)); //the origin
CGPathAddLineToPoint(thePath, NULL, pointA.x, pointA.y); //Point A
CGPathAddLineToPoint(thePath, NULL, pointB.x, pointB.y); //Point B
// Create an animation
CAKeyframeAnimation *originAnimation = [CAKeyframeAnimation animation];
originAnimation.path = thePath;
originAnimation.duration = 2.0f;
originAnimation.calculationMode = kCAAnimationPaced;
// Add this animation
[theView setAnimations:[NSDictionary dictionaryWithObjectsAndKeys: originAnimation, @”frameOrigin”, nil]];
// Activate this animation
[[theView animator] setFrameOrigin:pointB]; //set the point of the last frame