如何让视图永远旋转? [英] How to let a view rotate forever?
问题描述
有没有办法让视图以指定的速度永远旋转?我需要一个指标类型的东西。我知道有一个奇怪的Lxxxxx00ff常数(完全不记得它)代表永远。
Is there a way to let a view rotate forever, with an specified speed? I need that for an indicator kind of thing. I know there is this weird Lxxxxx00ff constant (don't remember it exactly) that stands for "forever".
推荐答案
你可以使用 HUGE_VAL
获取浮动值(如果我没记错的话,动画的repeatCount属性是浮点数)。
You can use HUGE_VAL
for floating value (if I remember correctly, repeatCount property for animation is a float).
要设置动画,您可以使用 + animationWithKeyPath创建CAAnimation对象:
方法:
To setup animation you can create CAAnimation object using +animationWithKeyPath:
method:
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"];
如果我记得使用UIView正确创建这种旋转动画是不可能的,因为旋转360度( 2 * M_PI弧度)被优化为完全没有旋转。
If I remember correctly creating this kind of rotation using just UIView animations is impossible because rotations on 360 degrees (2*M_PI radians) are optimized to no rotation at all.
这篇关于如何让视图永远旋转?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!