CALayer rotation from start angle

I want to constantly rotate the layer using byValue, but I cannot get it to work correctly. I want to rotate 6 degrees per second to have a full revolution in 60 seconds.

If the initial rotation of the layer is 0, everything is in order.

The problem is that I am trying to set the initial one fromValue. If I set it fromValueto 90 degrees, the animation will rotate from 90 to 90 + 6, then jump to 90+ (90 + 6), animate and jump again.

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"];
+3
source share
1 answer

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;
+8
source

Source: https://habr.com/ru/post/1709648/


All Articles