UIView 的 -drawRect:
方法是否必须在主线程上绘制,或者 CADisplayLink 是否可以在不同的运行循环中在自定义 View 上调用 -setNeedsDisplay
?
最佳答案
As of iOS 4.0 ,您可以在后台线程上的 UIView 的 -drawRect:
中绘制:
- Drawing to a graphics context in UIKit is now thread-safe. Specifically:
- The routines used to access and manipulate the graphics context can now correctly handle contexts residing on different threads.
- String and image drawing is now thread-safe.
- Using color and font objects in multiple threads is now safe to do.
另请参阅他们在 Technical Q&A QA1637 中的评论在 iOS 4.0 中对此进行了说明。
在此之前的任何版本的 iOS 仍然需要将此绘图放在主线程上。
关于iphone - UIView 的 -drawRect 是否为 : have to be called on the main thread?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5182686/