[英]Rotate 3d AR object 360 degree using touch with ARToolkit ios+sdk
[英]How to rotate a view in 3d by 360 degree?
我正在开发一个应用程序,其中我将视图旋转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"];
动画完成后会反转,因为您将autoreverses
反转设置为YES
。 这就是自动autoreverses
作用。
至于为什么要旋转180度而不是360度... 360度是多少弧度?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.