2009-06-03 6 views
3

Je souhaite faire pivoter un calque en continu à l'aide de byValue, mais je n'arrive pas à le faire fonctionner correctement. Je veux tourner de 6 degrés toutes les secondes, pour avoir une rotation complète en 60 secondes.Rotation d'un CALayer à partir d'un angle de début

Si la rotation initiale du calque est 0, tout est OK. Le problème est quand j'essaye de placer un fromValue initial. Si je mets le fromValue à 90 degrés, l'animation tournera de 90 à 90 + 6, puis passera à 90+ (90 + 6), animera et sautera à nouveau.

Une idée?

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

Répondre

8

Cela fonctionne pour moi:

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; 
Questions connexes