从起始角度旋转CALayer

时间:2009-06-03 07:07:15

标签: iphone cocoa-touch core-animation

我想使用byValue连续旋转图层,但我无法使其正常工作。 我希望每秒旋转6度,在60秒内完全旋转。

如果图层的初始旋转为0,则一切正常。

问题在于我尝试设置初始fromValue。如果我将fromValue设置为90度,动画将从90度旋转到90 + 6,然后跳转到90+(90 + 6),动画并再次跳转。

有什么想法吗?

CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];

animation.fromValue = [NSNumber numberWithDouble:M_PI_2];
animation.byValue = [NSNumber numberWithDouble:6.0f*M_PI/180.0f];
animation.toValue = nil;

animation.fillMode = kCAFillModeForwards;
animation.cumulative = YES;
animation.additive = NO;
animation.repeatCount = 10000;
animation.removedOnCompletion = YES;
animation.duration = 1.0;
[myLayer addAnimation:animation forKey:@"transform"];

1 个答案:

答案 0 :(得分:8)

这对我有用:

CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath: @"transform"];
CATransform3D transform = CATransform3DMakeRotation (DegreesToRadians (90), 0, 0, 1);
animation.toValue = [NSValue valueWithCATransform3D: transform];
animation.duration = 60;
animation.cumulative = NO;
animation.repeatCount = 10000;
animation.removedOnCompletion = YES;