我想要一个 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/