如何将视图在3d中旋转360度?

时间:2012-05-31 05:31:09

标签: iphone objective-c ios rotation catransformlayer

我正在开发一个应用程序,我将360度旋转视图,但我无法将其旋转360度。 它旋转了180度,旋转后它回到原来的位置。

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

换句话说,它是来回旋转。 如何连续旋转.... 请帮助...

2 个答案:

答案 0 :(得分:0)

完成后动画正在反转,因为您将autoreverses设置为YES。这就是autoreverses所做的。

至于你为什么旋转180度而不是360度?有多少弧度是360度?

答案 1 :(得分:0)

这有点棘手但你可以在docs中找到它 要连续旋转它,首先需要设置toValue,然后将动画重复计数设置为HUGH_VALF(在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"];