【问题标题】:How to rotate a view in 3d by 360 degree?如何将 3d 视图旋转 360 度?
【发布时间】:2012-06-05 09:00:30
【问题描述】:

我正在开发一个应用程序,其中我将视图旋转 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

换句话说,它正在来回旋转。 如何连续旋转它...... 请帮忙...

【问题讨论】:

    标签: iphone objective-c ios rotation catransformlayer


    【解决方案1】:

    这有点棘手,但您可以在 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"];
    

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

      • 2 弧度,但每当我写 2 时它甚至都不动
      • 您可能想check your math。此外,您可能会发现常量 M_PI 很有帮助。
      • 我的意思是 180*2 ...即使我写了 6.28 但没有结果..请帮助
      猜你喜欢
      • 1970-01-01
      • 2013-03-15
      • 1970-01-01
      • 2020-01-11
      • 1970-01-01
      • 2016-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多