views:

1279

answers:

1

I want to rotate a layer continuously using byValue, but I can't make it work correctly. I want to rotate by 6 degrees every second, to have a full rotation in 60 seconds.

If the initial rotation of the layer is 0, everything is OK.

The problem is when I try to set an initial fromValue:
If I set the fromValue to 90 deg, the animation will rotate from 90 to 90+6, then jump to 90+(90+6), animate, and jump again.

Any idea?

Stephan

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"];
+2  A: 

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;
Fabrice Truillot de Chambrier