旋转CALayer从起始角度

3
我想使用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个回答

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;

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接