Pregunta

I am developing an app in which i am rotating a view by 360 degree but i am not able to rotate it 360 degree. It is getting rotated by 180 degree and after getting rotated it is coming back to it's original position..

animation = [CABasicAnimation animationWithKeyPath:@"transform"];
transform = CATransform3DMakeRotation(3.14f, 1.0f, 1.0f, 1.0f);  
value = [NSValue valueWithCATransform3D:transform]; 
[animation setToValue:value];
[animation setAutoreverses:YES]; 
[animation setDuration:0.9];
[[rotatBall layer] addAnimation:animation forKey:@"180"];  //rotatBall is a view

In other words,it is making back and forth rotation. How to rotate it continuously.... Kindly help...

¿Fue útil?

Solución

That's a little bit tricky but you can find it in the docs.
To rotate it continuously you first need to set the toValue then set the animation repeat count to HUGH_VALF (defined in math.h).

    CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.x"];

    transform = CATransform3DMakeRotation(1.0f, 1.0f, 1.0f, 1.0f);  
    fromValue = [NSValue valueWithCATransform3D:transform];

    transform = CATransform3DMakeRotation(M_PI*2, 1.0f, 1.0f, 1.0f);  
    toValue = [NSValue valueWithCATransform3D:transform];

    animation.fromValue = fromValue;
    animation.toValue = toValue;
    animation.duration = 0.9f; 
    animation.repeatCount = HUGE_VALF;     // HUGE_VALF is defined in math.h so import it
    [rotatBall.layer addAnimation:animation forKey:@"rotation"];

Otros consejos

Your animation is reversing after it finishes because you set autoreverses to YES. That's what autoreverses does.

As for why you're rotating by 180 degrees instead of 360... how many radians is 360 degrees?

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top