动画旋转 UIImageView
我想将 UIImageView
向左/向右旋转大约 10 度,但要有平滑的动画,而不是我看到的突然转向:
player.transform = CGAffineTransformMakeRotation(angle)
I want to rotate a UIImageView
by roughly 10 degrees left/right but have a smooth animation, rather than a sudden turn which I see using:
player.transform = CGAffineTransformMakeRotation(angle)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我使用一些类似的代码来实现类似的效果(尽管我将其旋转 360 度):
我使用与此非常相似的代码来旋转图像视图。
I use some code like this to achieve a similar effect (though I rotate it by 360 degrees):
I use code very similar to this to spin an image view.
转换为 Swift 3/4:
Converted for Swift 3/4:
我有一些代码旋转 360 度:
调用它:
[self runSpinAnimationOnView:imgViewuration:0.1rotations:M_PI_4repeat:10];
动画旋转一些度并再次:
如果你想旋转 uiimageview左/右大约 10 度
调用:
[selfrotateImage:imgView持续时间:0.7延迟:0.0曲线:UIViewAnimationCurveEaseIn旋转:(M_PI/18)];
相似,某种程度
i have some code rotate 360 degrees:
call it:
[self runSpinAnimationOnView:imgView duration:0.1 rotations:M_PI_4 repeat:10];
And animation rotate some degrees and again:
If you want to rotate a uiimageview by roughly 10 degrees left/right
call :
[self rotateImage:imgView duration:0.7 delay:0.0 curve:UIViewAnimationCurveEaseIn rotations:(M_PI/18)];
similar, some degress
使用
NSTimer
和CGAffineTransformMakeRotation
的现代Swift
解决方案:需要注意的事项:
将插座连接到
UIImageView
>使用 (1) 计时器速度、(2) 动画速度和 (3) 旋转角度来获得所需的结果。这组变量对我有用。
A modern
Swift
solution, usingNSTimer
andCGAffineTransformMakeRotation
:Things to notice:
Connect the outlet the the
UIImageView
Play with the (1)timer pace, (2)animation pace and (3)rotation angle to get the desired results. This set of variables worked for me.