我有一个需要显示的弹出窗口,直到所有的图像都上传到视图控制器上,我使用dispatch-async方法在所有图像上传之前显示弹出窗口,并在图像显示时隐藏。
但在调用dispatch_async方法时,UIView屏幕冻结显示挂起弹出窗口,这是我在代码中出错的地方,或者是实现这一点的最好方法。
func imageIconTapped(gesture: UITapGestureRecognizer){
self.loadingPopUp = showPopUp(self, txt: “Processing..")
self.navigationController!.view.addSubview(self.loadingPopUp!)
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {
code to getting the image // getting the images is time taking therefore it work in the background.
dispatch_async(dispatch_get_main_queue()) {
method to upload the images on the view controller and hide the popup.
}发布于 2016-06-27 20:17:03
函数"imageIconTapped“是已经在主thread.So上运行的UIKit方法,不需要将代码分派到主队列。
当您将代码从主线程分派到主队列时,主线程被阻塞。
https://stackoverflow.com/questions/38053008
复制相似问题