objective-c – 顺时针旋转UIImageView
发布时间:2020-12-16 05:56:48 所属栏目:百科 来源:网络整理
导读:这应该很简单,但是我无法使UI ImageView完整360度旋转,永远重复. [UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionRepeat | UIViewAnimationOptionCurveLinear | UIViewAnimationOption
这应该很简单,但是我无法使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相同.
解决方法
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所述,这将导致动画永远重复. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |