顺时针旋转UIImageView

编程入门 行业动态 更新时间:2024-10-09 07:21:35
本文介绍了顺时针旋转UIImageView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这应该很简单,但是我无法将 UIImageView 旋转360度,一直重复一次。

This should be simple, but I'm having trouble rotating a UIImageView a full 360 degrees, repeated forever.

[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 相同。

According to the docs, the signedness of the angle I pass to CGAffineTransformRotate determines the direction of the rotation, but the above code rotates counterclockwise. Same with M_PI.

矩阵旋转的角度(以弧度为单位)坐标系统轴。在iOS中,正值指定逆时针旋转,负值指定顺时针旋转。在Mac OS X中,正值指定顺时针旋转,而负值指定逆时针旋转。

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已经按照正确的方式进行操作,但是还有一种更好的方法来使它保持旋转,而无需在每次结束时在动画委托中重新调用它。这是完全错误的。

Christoph is already going the correct way, but there is a far better way to keep it spinning without reinvoke it in the animation delegates every time it ends. This is simply wrong.

只需将动画的repeatCount属性设置为 HUGE_VALF 。

Just set the repeatCount property of your animation to 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"];

如,这将使动画永远重复。

As stated in the documentation, this will cause the animation to repeat forever.

更多推荐

顺时针旋转UIImageView

本文发布于:2023-11-30 13:26:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1650143.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:顺时针   UIImageView

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!