Rotate UIButton 360 degrees(旋转 UIButton 360 度)
本文介绍了旋转 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 度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:旋转 UIButton 360 度


猜你喜欢
- Xcode 7.3 中带有 UILabel 的 UIStackView 2022-01-01
- 网上有没有好的 UIScrollView 教程? 2022-01-01
- 在 Iphone SDK 的导航栏上添加多个按钮 2022-01-01
- 如何在 iPhone 模拟器中重置 NSUserDefaults 数据? 2022-01-01
- 类似于 Mail.app 的 iPad 模态视图控制器? 2022-01-01
- URL编码Swift iOS 2022-01-01
- 使用自动布局向 UIScrollView 添加动态大小的视图 2022-01-01
- UITextView 内容插图 2022-01-01
- SetOnItemSelectedListener上的微调程序错误 2022-01-01
- GPS状态的广播接收器? 2022-01-01