gpt4 book ai didi

swift - 跟踪totalBytesSent会阻止动画几秒钟

转载 作者:行者123 更新时间:2023-11-30 13:29:14 25 4
gpt4 key购买 nike

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

在上传过程中,我想显示一个进度指示器。然而,任何需要刷新显示的代码命令似乎都不会在几秒钟之前执行。

例如下面的代码,当数据开始发送时,PROGRESS会立即出现在控制台中,但顶部 View 只会在大约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


}

知道为什么吗?

提前非常感谢您的帮助。

拉斐尔

最佳答案

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

dispatch_async(dispatch_get_main_queue()) { [unowned self] in
//update UI hear
}

关于swift - 跟踪totalBytesSent会阻止动画几秒钟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36765611/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com