UIView drawing process
Let’s illustrate this process:
-
When we call the [UIView setNeedsDisplay] method, we do not perform an immediate draw.
-
After calling setNeedDisplay, the system will call setNeedsDisplay of the layer corresponding to view
-
Call the Layer display method near the end of the current RunLoop to enter the actual drawing of the current view.
-
Inside the layer display method, the system determines whether the layer’s layer.delegate implements the displayLayer: method, a. If not, execute the system’s drawing process; B. If it is implemented, it will enter the entrance of asynchronous drawing.
-
Finally, the backing Store will be handed over to the GPU.
Ii. System drawing process
Describe the process:
-
Inside the layer, a backing store is created, which we can interpret as a CGContextRef context.
-
Check whether the layer has a delegate: 2.1 If there is a delegate, [layer.delegate drawLayer:inContext] will be executed (this method is executed inside the system), and the view’s drawRect: method will be called within this method. That is, we override the view’s drawRect: method to get called. 2.2 If there is no delegate, the Layer’s drawInContext method, which we can override, will be called.
-
Finally, the backing Store will be handed over to the GPU.
For more information
This article is from: Wind and Rain “83”