将UIButton旋转360度 [英] Rotate UIButton 360 degrees
本文介绍了将UIButton旋转360度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在尝试使用以下代码运行动画,以将我的UIButton
360度旋转:
I've been trying to run an animation that rotates my UIButton
360 degrees using this code:
UIView.animateWithDuration(3.0, animations: {
self.vineTimeCapButton.transform = CGAffineTransformMakeRotation(CGFloat(M_PI*2))
self.instagramTimeCapButton.transform = CGAffineTransformMakeRotation(CGFloat(M_PI*2))
})
但是,它不会旋转360度,因为UIButton
已经在该位置.
However, it doesn't rotate 360 degrees because the UIButton
is already at that location.
如何将UIButton旋转360度?
How can I rotate my UIButton 360 degrees?
推荐答案
您可以使用一个技巧:先开始旋转180度,然后再旋转360度.延迟使用2个动画. 试试这个.
You can use a trick: start rotating with 180 degrees first and then rotate with 360 degrees. Use 2 animations with delay. Try this.
快捷键2
UIView.animateWithDuration(0.5) { () -> Void in
button.transform = CGAffineTransformMakeRotation(CGFloat(M_PI))
}
UIView.animateWithDuration(0.5, delay: 0.45, options: UIViewAnimationOptions.CurveEaseIn, animations: { () -> Void in
button.transform = CGAffineTransformMakeRotation(CGFloat(M_PI * 2))
}, completion: nil)
快速3、4、5
UIView.animate(withDuration: 0.5) { () -> Void in
self.settingsButton.transform = CGAffineTransform(rotationAngle: CGFloat.pi)
}
UIView.animate(withDuration: 0.5, delay: 0.45, options: UIViewAnimationOptions.curveEaseIn, animations: { () -> Void in
self.settingsButton.transform = CGAffineTransform(rotationAngle: CGFloat.pi * 2.0)
}, completion: nil)
希望这会有所帮助
这篇关于将UIButton旋转360度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文