Does UIView's -drawRect:
method have to be drawn on the main thread or can CADisplayLink call -setNeedsDisplay
on a custom view in a different run loop?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
All UIKit calls should be done on the main thread.
回答2:
As of iOS 4.0, you can draw within a UIView's -drawRect:
on a background thread:
- 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.
See also their comments in Technical Q&A QA1637 regarding this in iOS 4.0.
Any version of iOS before that still needs to have this drawing be on the main thread.