可以通过动画化层的transform.rotation
关键路径的动画,通过围绕其Z轴的一个(或多个)完全旋转的层,这样的:
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
animation.duration = .25;
animation.fromValue = [NSNumber numberWithFloat:0];
animation.toValue = [NSNumber numberWithFloat:2 * M_PI];
[layer addAnimation:animation forKey:animation.keyPath];
可以绕X或Y轴动画使用关键路径transform.rotation.x
和transform.rotation.y
。 (关键路径transform.rotation.z
与关键路径transform.rotation
具有相同的效果。)可以同时在单独的轴上应用多个旋转。
另一种方式来做到这一点,如果你想绕离轴载体,它可能工作得更好,是使用关键帧动画,就像这样:
CALayer *layer = [sender layer];
CATransform3D transform = CATransform3DIdentity;
transform.m34 = 1.0/-50;
layer.transform = transform;
CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
animation.values = [NSArray arrayWithObjects:
[NSValue valueWithCATransform3D:CATransform3DRotate(transform, 0 * M_PI/2, 100, 1, 100)],
[NSValue valueWithCATransform3D:CATransform3DRotate(transform, 1 * M_PI/2, 100, 1, 100)],
[NSValue valueWithCATransform3D:CATransform3DRotate(transform, 2 * M_PI/2, 100, 1, 100)],
[NSValue valueWithCATransform3D:CATransform3DRotate(transform, 3 * M_PI/2, 100, 1, 100)],
[NSValue valueWithCATransform3D:CATransform3DRotate(transform, 4 * M_PI/2, 100, 1, 100)],
nil];
animation.duration = 2;
[layer addAnimation:animation forKey:animation.keyPath];
你们是不是要旋转180分或360度?因为我认为360度旋转与完全不旋转相同。 – htinlinn 2012-07-20 01:16:54
@htinlinn我认为他正在尝试通过完整的360度旋转对他的图层进行动画制作。 – 2012-07-20 03:16:30
@robmayoff啊。好。 – htinlinn 2012-07-20 03:51:48