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?
Asked
Active
Viewed 2,161 times
0
Brad Larson
- 169,393
- 45
- 393
- 567
dubbeat
- 7,567
- 18
- 67
- 116
2 Answers
10
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.
Brad Larson
- 169,393
- 45
- 393
- 567
2
All UIKit calls should be done on the main thread.
Jeff Kelley
- 18,860
- 6
- 69
- 80
-
2As I explain in my answer, as of iOS 4.0 you can indeed draw to a UIView within a background thread. – Brad Larson Dec 16 '11 at 20:29