Swift Bar Button Item 60 Spin?(Swift Bar Button Item 60 Spin?)
我之前在这里看到过类似的问题,但它们只涉及简单的按钮,而不是条形按钮项。 请记住,栏按钮项和常规按钮具有不同的属性,因此其他帖子的答案在这种情况下不起作用。
有一种方法,在swift中,我可以使我的刷新条按钮项目旋转一次60度(以显示发生了一个动作)?
I have seen similar questi on here before, but they relate to just simple butt, not bar button items. Keep in mind- bar button items and regular butt have different properties, thus the answers on the other posts will not work in this situation.
Is there a way, in swift, that I can make my refresh bar button item spin 60 degrees one time (to show that an action occurred)?
最满意答案
为了动画化UIBarButtonItem ,我们需要为它分配一个customView并为其设置动画。
我在下面做的是创建一个普通的UIButton ,并将它的图像分配给名为“refresh”的刷新图标。 接下来,我将我的UIBarButtonItem的customView设置为我的新按钮。 现在barButton有一个customView ,我可以调用我的rotateBarButton()方法来执行动画代码。
import UIKit class ViewController: UIViewController { @IBOutlet weak var barButton: UIBarButtonItem! override func viewDidLoad() { super.viewDidLoad() let button = UIButton(frame: CGRectMake(0, 0, 40, 40)) // Create new button & set its frame button.setImage(UIImage(named: "refresh"), forState: .ormal) // Assign an image = button // Set as barButton's customView } func rotateBarButton() { // Gets you half way there // UIView.animateWithDuration(0.05, delay: 0.0, opti: UIViewAnimationOpti.CurveEaseIn, animati: { self.?.transform = CGAffineTransformMakeRotation(CGFloat(M_PI)) }, completion: nil) // Rotates all the way around // UIView.animateWithDuration(0.5, delay: 0.5, opti: UIViewAnimationOpti.CurveEaseIn, animati: { self.?.transform = CGAffineTransformMakeRotation(CGFloat(M_PI * 2)) }, completion: nil) } }In order to animate a UIBarButtonItem, we need to assign it a customView and animate that instead.
What I've done below is create an ordinary UIButton, and I've assigned it's image to a refresh icon named "refresh". ext, I set my UIBarButtonItem's customView to be my new button. ow that barButton has a customView, I can call my rotateBarButton() method to perform the animation code.
import UIKit class ViewController: UIViewController { @IBOutlet weak var barButton: UIBarButtonItem! override func viewDidLoad() { super.viewDidLoad() let button = UIButton(frame: CGRectMake(0, 0, 40, 40)) // Create new button & set its frame button.setImage(UIImage(named: "refresh"), forState: .ormal) // Assign an image = button // Set as barButton's customView } func rotateBarButton() { // Gets you half way there // UIView.animateWithDuration(0.05, delay: 0.0, opti: UIViewAnimationOpti.CurveEaseIn, animati: { self.?.transform = CGAffineTransformMakeRotation(CGFloat(M_PI)) }, completion: nil) // Rotates all the way around // UIView.animateWithDuration(0.5, delay: 0.5, opti: UIViewAnimationOpti.CurveEaseIn, animati: { self.?.transform = CGAffineTransformMakeRotation(CGFloat(M_PI * 2)) }, completion: nil) } }#感谢您对电脑配置推荐网 - 最新i3 i5 i7组装电脑配置单推荐报价格的认可,转载请说明来源于"电脑配置推荐网 - 最新i3 i5 i7组装电脑配置单推荐报价格
推荐阅读
留言与评论(共有 12 条评论) |
本站网友 孕早期营养 | 11分钟前 发表 |
{ self.?.transform = CGAffineTransformMakeRotation(CGFloat(M_PI * 2)) } | |
本站网友 合肥建材团购 | 15分钟前 发表 |
"refresh") | |
本站网友 甲型hini流感 | 22分钟前 发表 |
有一种方法 | |
本站网友 钻石之争 | 23分钟前 发表 |
I set my UIBarButtonItem's customView to be my new button. ow that barButton has a customView | |
本站网友 红旗h7参数 | 24分钟前 发表 |
delay | |
本站网友 晶莹的什么 | 19分钟前 发表 |
UIBarButtonItem! override func viewDidLoad() { super.viewDidLoad() let button = UIButton(frame | |
本站网友 冠群金辰 | 24分钟前 发表 |
{ self.?.transform = CGAffineTransformMakeRotation(CGFloat(M_PI * 2)) } | |
本站网友 河南癫痫病医院哪家好 | 20分钟前 发表 |
CGRectMake(0 | |
本站网友 兴化租房 | 8分钟前 发表 |
nil) // Rotates all the way around // UIView.animateWithDuration(0.5 | |
本站网友 水烟怎么抽 | 12分钟前 发表 |
{ self.?.transform = CGAffineTransformMakeRotation(CGFloat(M_PI)) } | |
本站网友 治疗早泄的方法 | 7分钟前 发表 |
我将我的UIBarButtonItem的customView设置为我的新按钮 |