2012-05-31 102 views
1

我正在开发一个应用程序,其中我旋转了360度的视图,但我无法旋转360度。 已经越来越被旋转180度后得到旋转时,它正在回到它原来的位置..如何以360度旋转3D视图?

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 

换句话说,它正在来回转动。 如何不断旋转它.... 请帮助...

回答

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

你的动画扭转它完成之后,因为你设置autoreversesYES。这就是autoreverses所做的。

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

+0

2弧度,但每当我写2,它甚至不动 –

+0

你可能想[查看你的数学(http://www.google.com/search?q=how+many+radians+是+ 360 +度)。另外,你可能会发现常量M_PI有帮助。 – rickster

+0

我的意思是180 * 2 ...即使我写了6.28,但没有结果..请帮助 –