如何让视图永远旋转?

ope*_*rog 5 iphone core-animation uiview

有没有办法让视图以指定的速度永远旋转?我需要一个指标类型的东西.我知道有一个奇怪的Lxxxxx00ff常数(不记得它)代表"永远".

Vla*_*mir 20

您可以使用HUGE_VAL浮动值(如果我没记错的话,动画的repeatCount属性是一个浮点数).

要设置动画,您可以使用以下+animationWithKeyPath:方法创建CAAnimation对象:

CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
animation.fromValue = [NSNumber numberWithFloat:0.0f];
animation.toValue = [NSNumber numberWithFloat: 2*M_PI];
animation.duration = 3.0f;
animation.repeatCount = HUGE_VAL;
[rotView.layer addAnimation:animation forKey:@"MyAnimation"];
Run Code Online (Sandbox Code Playgroud)

如果我记得只使用UIView正确创建这种旋转动画是不可能的,因为360度旋转(2*M_PI弧度)被优化为根本没有旋转.