ios - 让 UIView drawRect 出现在后台线程中

标签 ios cocoa-touch uiview drawrect setneedsdisplay

我想要一个 UIView 子类来实现类似于 setNeedsDisplay 的方法,除了重绘(即通常通过 drawRect 调用: ) 将很快在后台线程中发生,而不是在当前更新周期结束时发生。

它可能被称为 setNeedsAsynchronousDisplay。或者现有的 setNeedsDisplay 可能会被劫持,并且不会在循环结束时导致重绘,或者其他任何情况,只要它让重绘不会发生在主线程上,阻塞屏幕更新交互直到完成。

在重绘发生之前, View 可以继续使用其当前绘制的表示。

按照这些思路合理可行吗?

谢谢!

最佳答案

是的,这是可能的。您可能需要在后台将内容 View 生成为图像并将图像推送到 nsdictionary 或数组中。

因此,当您的背景正在生成图像时,您可以通过渲染图像在 drawrect 函数中显示图像,前提是图像已经生成。

演示如何操作的 WWDC 视频:WWDC 2012 session 211 - Building Concurrent User Interfaces on IOS .这是视频说明:

For a great user experience, it's essential to keep your application responsive while it renders complex UI elements and processes data. Learn how to use concurrency at the UIKit layer to perform drawing and other common operations without blocking user interaction.

关于ios - 让 UIView drawRect 出现在后台线程中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21139300/

相关文章:

iphone - 是否可以通过编程方式更改应用程序图标?

ios - 如何将 Google MapView 放入 UIView 中?

ios - Cocos2D reload 白屏报错

android - 在开发多平台移动应用程序时,有哪些可用选项及其优缺点?

iphone - 不想在应用程序更新时替换旧数据库

IOS 在 UITableView 中点击 UILabel

ios - 将数据从我的 viewcontroller 类传递到放置在同一场景中的自定义类 UIView 时,“包装可选值时出现意外的 nil”

ios - 重新定位 UITableView

ios 8 opengl es 1.1 停产了吗?

ios - 在 iPhone App 中如何检测设备的屏幕分辨率