这应该很简单,但是我无法使UI
ImageView完整360度旋转,永远重复.
[UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionRepeat | UIViewAnimationOptionCurveLinear | UIViewAnimationOptionBeginFromCurrentState animations:^{ self.reloadButton.imageView.transform = CGAffineTransformRotate(self.reloadButton.imageView.transform,-M_PI); } completion:^(BOOL finished) { }];
根据文档,我传递给CGAffineTransformRotate的角度的有符号决定了旋转的方向,但上述代码逆时针旋转.与M_PI相同.
The angle,in radians,by which this matrix rotates the coordinate
system axes. In iOS,a positive value specifies counterclockwise
rotation and a negative value specifies clockwise rotation. In Mac OS
X,a positive value specifies clockwise rotation and a negative value
specifies counterclockwise rotation.
解决方法
Christoph已经走了正确的道路,但是有一个更好的方法来保持它的旋转,而不会在动画代表中每次都结束时重新启动它.这是错误的.
只需将动画的repeatCount属性设置为HUGE_VALF即可.
CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"]; animation.fromValue = @0.0f; animation.toValue = @(2*M_PI); animation.duration = 0.5f; // this might be too fast animation.repeatCount = HUGE_VALF; // HUGE_VALF is defined in math.h so import it [self.reloadButton.imageView.layer addAnimation:animation forKey:@"rotation"];
如in the documentation所述,这将导致动画永远重复.