iphone - 如何将 3d View 旋转 360 度?

标签 iphone objective-c ios rotation catransformlayer

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

相关文章:

ios - 在 Swift 中获取 No such module 'AWSS3'

iphone - 来自 View Controller 类中的某个类调用方法

ios - 为 uibutton ios 使用 TableView 披露指示器样式

iphone - 我是否需要像这段代码中那样在 viewDidLoad 中将这些变量设置为 nil ?

ios - 如何禁用工具栏项?

objective-c - MKAnnotationView 在收到事件时更新标题和副标题的距离

ios - 导航栏外观 barTintColor alpha 组件

iphone - CocoaPods 的团队合作问题

iphone - 为 iOS 开发时要提交哪些文件

php - json 从 mysql (使用 php) 到标签