Fry*_*Fry 0 objective-c uiviewanimation ios
我有这个代码无休止的旋转 UIImageView
[UIView animateWithDuration:0.3f
delay:0.0f
options:UIViewAnimationOptionCurveLinear|UIViewAnimationOptionRepeat
animations: ^{
self.spinner.transform = CGAffineTransformRotate(CGAffineTransformIdentity, -M_PI);
}
completion: ^(BOOL finished) {
}];
Run Code Online (Sandbox Code Playgroud)
但第一个我把这个方法称为图像,它顺时针旋转而不是逆时针旋转.如果我在图像旋转时重新调用此方法,它会改变方向并开始逆时针旋转.
想法?
使用a CABasicAnimation代替,因为它更强大.您只需调用以下代码段一次,动画将无限期运行:
CABasicAnimation *rotate = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
rotate.toValue = @(M_PI * 2); // use @(-M_PI * 2) for counter clockwise
rotate.duration = 0.3;
rotate.cumulative = true;
rotate.repeatCount = HUGE_VALF;
[self.spinner.layer addAnimation:rotate forKey:@"rotateAnim"];
Run Code Online (Sandbox Code Playgroud)
迅速:
let rotate = CABasicAnimation(keyPath: "transform.rotation.z")
rotate.toValue = M_PI * 2
rotate.duration = 0.3
rotate.cumulative = true
rotate.repeatCount = HUGE
self.spinner.layer.addAnimation(rotate, forKey: "rotateAnim")
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
318 次 |
| 最近记录: |