跟踪totalBytesSent阻止动画几秒钟

时间:2016-04-21 09:38:17

标签: swift upload progress

我目前正在使用Swift iPhone应用程序中的上传功能。

在上传过程中,我想显示进度指示器。但是,任何需要刷新显示的代码命令似乎都没有在几秒钟之前执行。

例如,使用下面的代码,当数据开始发送时,PROGRESS会立即显示在控制台中,但顶视图仅在大约10秒后消失。

    func URLSession(_ session: NSURLSession,
                  task task: NSURLSessionTask,
                       didSendBodyData bytesSent: Int64,
                                       totalBytesSent totalBytesSent: Int64,
                                                      totalBytesExpectedToSend totalBytesExpectedToSend: Int64) {
    //uploadProgressCallback(uploadProgressRatio: min(Double(totalBytesSent) / self.uploadedFileTotalSize, 1.0) )

    print("PROGRESS")
    let topController:UINavigationController = UIApplication.sharedApplication().keyWindow!.rootViewController as! UINavigationController
    topController.view.alpha = 0.0


}

知道为什么吗?

非常感谢您的任何帮助。

圣拉斐尔

1 个答案:

答案 0 :(得分:0)

仅从主线程更新UI以获得高效性能:

b