Helenr
用Core Animation,可以指定动画路径。下面例子实现一个物体下落再弹起的动画 [CATransaction begin]; [CATransaction setValue:[NSNumber numberWithFloat:ANIMATION_DURATION] forKey:kCATransactionAnimationDuration];
CAKeyframeAnimation *positionAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
CGMutablePathRef positionPath = CGPathCreateMutable(); CGPathMoveToPoint(positionPath, NULL, [theView layer].position.x, [theView layer].position.y); CGPathAddQuadCurveToPoint(positionPath, NULL, [theView layer].position.x, - [theView layer].position.y, [theView layer].position.x, [theView layer].position.y); CGPathAddQuadCurveToPoint(positionPath, NULL, [theView layer].position.x, - [theView layer].position.y * 1.5, [theView layer].position.x, [theView layer].position.y); CGPathAddQuadCurveToPoint(positionPath, NULL, [theView layer].position.x, - [theView layer].position.y * 1.25, [theView layer].position.x, [theView layer].position.y);
positionAnimation.path = positionPath;
positionAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]; [[theView layer] addAnimation:positionAnimation forKey:@"positionAnimation"]; CGPathRelease(positionPath); [CATransaction commit]; 当然,在[CATransaction begin];
...
[CATransaction commit];代码块中,你可以对一个或多个视图同时添加多个动画效果(如改变其颜色、大小等),来实现更为复杂的动画