我试图在我们的应用程序显示一个旋转活动指示器,当用户点击一个按钮然后显示下一个视图 - 它有点工作,我看到它一瞬间
@IBOutlet weak var myActivityIndicator: UIActivityIndicatorView!
@IBOutlet weak var eventsbtn: UIButton!
@IBOutlet weak var pubsbtn: UIButton!
override func viewWillAppear(animated: Bool) {
myActivityIndicator.stopAnimating()
myActivityIndicator.hidden = true
}
override func viewDidLoad() {
super.viewDidLoad()
eventsbtn.layer.cornerRadius = 8
pubsbtn.layer.cornerRadius = 8
}
@IBAction func getEvents(sender: AnyObject) {
myActivityIndicator.hidden = false
myActivityIndicator.startAnimating()
}
答案 0 :(得分:0)
重构您的代码。您无需在viewWillAppear
中停止活动指示器。您可以在viewDidLoad
中隐藏它。这是代码:
@IBOutlet weak var myActivityIndicator: UIActivityIndicatorView!
@IBOutlet weak var eventsbtn: UIButton!
@IBOutlet weak var pubsbtn: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
eventsbtn.layer.cornerRadius = 8
pubsbtn.layer.cornerRadius = 8
myActivityIndicator.hidden = true
}
@IBAction func getEvents(sender: AnyObject) {
myActivityIndicator.hidden = false
myActivityIndicator.startAnimating()
}
确保在Interface Builder中正确连接活动指示符的IBOutlet
和获取事件的IBAction
。
答案 1 :(得分:0)
我改变它并且它不起作用,直到我回到导航
@IBOutlet weak var myActivityIndicator: UIActivityIndicatorView!
@IBOutlet weak var eventsbtn: UIButton!
@IBOutlet weak var pubsbtn: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
myActivityIndicator.stopAnimating()
myActivityIndicator.hidden = true
eventsbtn.layer.cornerRadius = 8
pubsbtn.layer.cornerRadius = 8
}
@IBAction func getEvents(sender: AnyObject) {
myActivityIndicator.hidden = false
myActivityIndicator.startAnimating()
}
答案 2 :(得分:0)
viewDidAppear可能是一个更适合停止动画并隐藏微调器的地方。