有没有办法让视图以指定的速度永远旋转?我需要它来作为指标之类的东西。我知道有一个奇怪的 Lxxxxx00ff 常量(记不太清了)代表“永远”。
您可以使用HUGE_VAL
对于浮动值(如果我没记错的话,动画的repeatCount属性是一个浮动值)。
要设置动画,您可以使用以下命令创建 CAAnimation 对象+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 弧度)的旋转被优化为根本不旋转。
编辑:添加了 Swift 版本。
let animation = CABasicAnimation(keyPath: "transform.rotation.z")
animation.fromValue = NSNumber(value: 0.0)
animation.toValue = NSNumber(value: 2*Double.pi)
animation.duration = 3.0
animation.repeatCount = Float.greatestFiniteMagnitude
rotView.layer.add(animation, forKey: "MyAnimation")
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)