简体   繁体   English

从起始角度旋转CALayer

[英]Rotating a CALayer from a start angle

I want to rotate a layer continuously using byValue , but I can't make it work correctly. 我想使用byValue连续旋转图层,但是无法使其正常工作。 I want to rotate by 6 degrees every second, to have a full rotation in 60 seconds. 我想每秒旋转6度,以在60秒内完全旋转。

If the initial rotation of the layer is 0, everything is OK. 如果图层的初始旋转为0,则一切正常。

The problem is when I try to set an initial fromValue . 问题是当我尝试设置初始fromValue If I set the fromValue to 90 degrees, the animation will rotate from 90 to 90+6, then jump to 90+(90+6), animate, and jump again. 如果将fromValue设置为90度,则动画将从90旋转到90 + 6,然后跳转到90+(90 + 6),进行动画处理,然后再次跳转。

Any idea? 任何的想法?

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"];

This works for me: 这对我有用:

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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM