我正在开发一个应用程序,我在其中将 View 旋转 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
换句话说,就是来回旋转。 如何连续旋转它...... 请帮助...
最佳答案
这有点棘手,但您可以在 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"];
关于iphone - 如何将 3d View 旋转 360 度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10827926/