You have some kind of custom UIView
which implements some awesome drawing in -[UIView drawRect:]
. In order to have UIKit draw it for you, you send the -[UIView setNeedsDisplay]
to the view object to queue it up for drawing.
*------------* *------------*
| | | |
| UIView | ------> | CALayer |
| | | |
*------------* *------------*
-[UIView setNeedsDisplay] -[CALayer setNeedsDisplay]
The UIView
object has another, special object backing it, a CALayer
. When its convenient for the rendering system, it'll ask the view's CALayer
to display by sending it the -[CALayer display]
message.
Now, the CALayer
creates a region of memory called a "Backing Store," a bitmap that stores the result of all the rendering operations.
*------------* *------------* ..............
| | | | . .
| UIView | ------> | CALayer | -----> . Backing .
| | | | . Store .
*------------* *------------* ..............
-[CALayer display]
This backing store image can be displayed on screen repeatedly until the view needs some different drawing (e.g., for a highlighted state). At that point, the process would start over by sending the view the -[UIView setNeedsDisplay]
message.
For a better walk through, check out the in-depth aside on UIView drawing in the WWDC 2012 presentation, Building Concurrent User Interfaces on iOS by Andy Matuschak (video requires an ADC login).