Does UIView's -drawRect: have to be called on

2019-09-14 07:58发布

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?

2条回答
成全新的幸福
2楼-- · 2019-09-14 08:32

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.

查看更多
\"骚年 ilove
3楼-- · 2019-09-14 08:38

All UIKit calls should be done on the main thread.

查看更多
登录 后发表回答