Drawing asynchronously
Uikit's single-threaded nature means that boarding maps are updated on the main thread, which means that drawing interrupts user interaction and even makes the entire app appear unresponsive. There's nothing we can do about it, but it's much better to avoid the user waiting for the drawing to finish.
There are some ways to do this: in some cases, we can presumably draw the content on another thread ahead of time, and then set the resulting picture directly to the content of the layer. This may not be convenient to implement, but it is feasible in certain situations. Core Animation offers some options: CATiledLayer and drawsasynchronously properties.
Catiledlayer
We explored it briefly in the sixth chapter CATiledLayer . In addition to splitting the layer again into a small, independent update (similar to the concept of automatic updating of dirty rectangles), CATiledLayer There is an interesting feature: calling a method on multiple threads for each small block at the same time -drawLayer:inContext: . This avoids blocking user interaction and being able to draw faster with multi-core new slices. Only one small piece CATiledLayer is an easy way to implement an asynchronous update of a picture view.
drawsasynchronously
ios 6, Apple introduced this curious property for Calayer , drawsasynchronously property for incoming -drawlayer:incontext: cgcontext changes to allow cgcontext to delay the execution of the drawing command so that user interaction is not blocked.
Catiledlayer . Its own -drawlayer:incontext: The method is only called on the main thread, but Cgcontext does not wait for the end of each drawing command. Instead, it joins the command into the queue and, when the method returns, performs a real drawing on a per-background thread.
According to Apple's statement. This feature works best on views that require frequent redrawing (such as our drawing app, or something like that UITableViewCell ), and is not much help for layers that are drawn only once or rarely redrawn.
Summarize
In this chapter we discuss some of the performance challenges with the core graphics software drawing, and then explore some improvements: such as improving drawing performance or reducing the amount of paint that needs to be drawn.
[IOS Animation]-calayer Drawing efficiency-asynchronous drawing