【问题标题】:UIView screen freeze when calling dispatch_async(dispatch_get_main_queue())调用 dispatch_async(dispatch_get_main_queue()) 时 UIView 屏幕冻结
【发布时间】:2016-06-27 11:39:09
【问题描述】:

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

但是UIView 屏幕在调用dispatch_async 方法时冻结显示挂起弹出窗口,其中我的代码有误,或者实现此目的的最佳方法是什么。

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.            
        }

【问题讨论】:

  • 如果没有看到您对图像做了什么,我们无法判断为什么需要这么长时间。您可以发布其余代码吗?
  • 其实我需要在没有上传图片的时候显示弹窗,当调用dispatch_async(dispatch_get_main_queue)时弹出显示但是uiview冻结,这里是发送图片的方法。
  • 感谢您的快速回复,现已解决。

标签: ios swift dispatch-async


【解决方案1】:

函数“imageIconTapped”是UIKit方法,已经在主线程上运行。所以不需要将代码调度到主队列。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多