Drawing in a background thread on iOS

前端 未结 2 907
既然无缘
既然无缘 2021-01-01 00:54

I have a view with some very complex drawing logic (it\'s a map view that draws from GIS data). Doing this drawing on the main thread locks up the UI and makes the app unres

2条回答
  •  佛祖请我去吃肉
    2021-01-01 01:45

    Beyond iOS 4.0, drawing is thread safe. You might need to create a CGContext yourself, but there is no reason you cannot draw on a background thread.

    That said, most UIKit operations are not. If you need to do those, you can always prepare in a background thread, and then use performOnMainThread when needed. There's even waitUntilDone. That said, you should use NSOperation and NSOperationQueue, apparently.

提交回复
热议问题