ios - QoS 用户交互和更新 UI

标签 ios multithreading uikit grand-central-dispatch

在 iOS 上,UI 应该只通过主线程更新,但令我感兴趣的是在文档中,用户交互服务质量是这样定义的:

Work that is interacting with the user, such as operating on the main thread, refreshing the user interface, or performing animations. If the work doesn’t happen quickly, the user interface may appear frozen. Focuses on responsiveness and performance.

问题是,如果您使用该 QoS 调用 dispatch_get_global_queue,返回的队列将不是主队列,对吗?因此,提交到该队列的工作如何刷新 UI?

谢谢。

最佳答案

Dispatch_get_global_queue 总会给你全局并发队列。您不能像在主队列之外的任何队列中那样更新该队列中的用户界面。

与用户交互 Qos 一样,它用于对 ui 至关重要的工作,并且需要尽快获得结果。

一个很好的例子是您有一张需要处理的图像。您可以使用用户交互 Qos 处理 global_queue 中的图像,完成后将结果图像设置在 imageView 中(这是在主队列中完成的)。

关于ios - QoS 用户交互和更新 UI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37424003/

相关文章:

ios - 无法将数据传递给下一个ViewController依赖于UIPickerView textField.text?

multithreading - 为什么我在使用 Async.Parallel 时只有一个线程 id?

ios - UIPoverController 每次使用时都会创建实时字节

ios - 使用 iTunes 中的歌曲制作本地播放列表

c++ - 多线程池分配器

c# - 从 WCF 服务启动多个任务

iphone - 以编程方式清除字段后,如何删除 UITextField 中出现的 "ghost"文本?

ios - rightBarButtonItem 出现在 NavigationBar 的中央

ios - 如何使用 drawRect 方法检测绘制项目上的触摸事件?

ios - UIView setNeedsDisplay 没有效果?