Activity 指标在 PHPhotoLibrary.sharedPhotoLibrary().performChanges 内部动作缓慢
Activity indicator acting slow inside PHPhotoLibrary.sharedPhotoLibrary().performChanges
我正在删除一些照片资产,我想在资产被删除时显示一个 activity 指示器,并在资产被删除但我的代码运行缓慢时停止它,你知道吗错了吗?
PHPhotoLibrary.sharedPhotoLibrary().performChanges({
PHAssetChangeRequest.deleteAssets(enumeration)
self.activityIndicator.startAnimating()
UIApplication.sharedApplication().beginIgnoringInteractionEvents()
}, completionHandler: {success, error in
if success {
self.activityIndicator.stopAnimating()
UIApplication.sharedApplication().endIgnoringInteractionEvents()
println("Success")
} else {
self.activityIndicator.stopAnimating()
UIApplication.sharedApplication().endIgnoringInteractionEvents()
println("Error")
}
})
我自己解决了,这里是答案:
PHPhotoLibrary.sharedPhotoLibrary().performChanges({
PHAssetChangeRequest.deleteAssets(enumeration)
let delay = 1 * Double(NSEC_PER_SEC)
let time = dispatch_time(DISPATCH_TIME_NOW, Int64(delay))
dispatch_after(time, dispatch_get_main_queue()) {
self.activityIndicator.startAnimating()
}
}, completionHandler: {success, error in
UIApplication.sharedApplication().beginIgnoringInteractionEvents()
if success {
println("good")
dispatch_async(dispatch_get_main_queue()){
self.activityIndicator.stopAnimating()
self.navigationController?.popToRootViewControllerAnimated(true)
}
UIApplication.sharedApplication().endIgnoringInteractionEvents()
} else {
println("bad")
dispatch_async(dispatch_get_main_queue()){
self.activityIndicator.stopAnimating()
}
UIApplication.sharedApplication().endIgnoringInteractionEvents()
}
})
只需添加:
dispatch_async(dispatch_get_main_queue()){
self.activityIndicator.stopAnimating()
}
我正在删除一些照片资产,我想在资产被删除时显示一个 activity 指示器,并在资产被删除但我的代码运行缓慢时停止它,你知道吗错了吗?
PHPhotoLibrary.sharedPhotoLibrary().performChanges({
PHAssetChangeRequest.deleteAssets(enumeration)
self.activityIndicator.startAnimating()
UIApplication.sharedApplication().beginIgnoringInteractionEvents()
}, completionHandler: {success, error in
if success {
self.activityIndicator.stopAnimating()
UIApplication.sharedApplication().endIgnoringInteractionEvents()
println("Success")
} else {
self.activityIndicator.stopAnimating()
UIApplication.sharedApplication().endIgnoringInteractionEvents()
println("Error")
}
})
我自己解决了,这里是答案:
PHPhotoLibrary.sharedPhotoLibrary().performChanges({
PHAssetChangeRequest.deleteAssets(enumeration)
let delay = 1 * Double(NSEC_PER_SEC)
let time = dispatch_time(DISPATCH_TIME_NOW, Int64(delay))
dispatch_after(time, dispatch_get_main_queue()) {
self.activityIndicator.startAnimating()
}
}, completionHandler: {success, error in
UIApplication.sharedApplication().beginIgnoringInteractionEvents()
if success {
println("good")
dispatch_async(dispatch_get_main_queue()){
self.activityIndicator.stopAnimating()
self.navigationController?.popToRootViewControllerAnimated(true)
}
UIApplication.sharedApplication().endIgnoringInteractionEvents()
} else {
println("bad")
dispatch_async(dispatch_get_main_queue()){
self.activityIndicator.stopAnimating()
}
UIApplication.sharedApplication().endIgnoringInteractionEvents()
}
})
只需添加:
dispatch_async(dispatch_get_main_queue()){
self.activityIndicator.stopAnimating()
}