我一直在尝试使用以下代码运行将我的 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 度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!