首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >调用dispatch_async(dispatch_get_main_queue())时UIView屏幕冻结

调用dispatch_async(dispatch_get_main_queue())时UIView屏幕冻结
EN

Stack Overflow用户
提问于 2016-06-27 19:39:10
回答 1查看 356关注 0票数 1

我有一个需要显示的弹出窗口,直到所有的图像都上传到视图控制器上,我使用dispatch-async方法在所有图像上传之前显示弹出窗口,并在图像显示时隐藏。

但在调用dispatch_async方法时,UIView屏幕冻结显示挂起弹出窗口,这是我在代码中出错的地方,或者是实现这一点的最好方法。

代码语言:javascript
复制
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.            
        }
EN

回答 1

Stack Overflow用户

发布于 2016-06-27 20:17:03

函数"imageIconTapped“是已经在主thread.So上运行的UIKit方法,不需要将代码分派到主队列。

当您将代码从主线程分派到主队列时,主线程被阻塞。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38053008

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档