我在我的按钮上添加了一个活动指示器,并在按下按钮时为其设置动画,但是,每次动画都是动画,但是无法看到,这是我的代码:
DispatchQueue.global(qos: .userInitiated).async {
self.openCircle(withCenter: sender.center, dataSource: self.calculator!.iterateWPItems()){}
DispatchQueue.main.sync {
self.activityIndicator.stopAnimating()
}
}
activityIndicator.startAnimating()
答案 0 :(得分:0)
只需在completion handler
中写一下。无需使用dispatch_after
self.activityIndicator.startAnimating()
print(activityIndicator.isAnimating)
openCircle(withCenter: sender.center, dataSource: calculator!.iterateWPItems()){
// place webservice data processing here
dispatch_async(dispatch_get_main_queue()) {
activityIndicator.stopAnimating();
}
}
斯威夫特3:
self.activityIndicator.startAnimating()
print(activityIndicator.isAnimating)
openCircle(withCenter: sender.center, dataSource: calculator!.iterateWPItems()){
// place webservice data processing here
DispatchQueue.main.async {
self.activityIndicator.stopAnimating()
}
}
答案 1 :(得分:0)
假设您的openCircle
方法是异步方法。我认为当您收到方法回叫时,您应该停止活动指示。请尝试修改此代码。
self.activityIndicator.startAnimating()
print(activityIndicator.isAnimating)
openCircle(withCenter: sender.center, dataSource: calculator!.iterateWPItems()){
dispatch_async(dispatch_get_main_queue()) {
activityIndicator.stopAnimating();
}
}
对于Swift 3,
self.activityIndicator.startAnimating()
print(activityIndicator.isAnimating)
openCircle(withCenter: sender.center, dataSource: calculator!.iterateWPItems()){
DispatchQueue.main.async {
self.activityIndicator.stopAnimating()
}
}
使用NSOperation,
self.activityIndicator.startAnimating()
print(activityIndicator.isAnimating)
openCircle(withCenter: sender.center, dataSource: calculator!.iterateWPItems()){
OperationQueue.main.addOperation {
self.activityIndicator.stopAnimating()
}
}