## UIView Drawing Model ### `-[UIView setNeedsDisplay]` 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. ### `-[CALayer setNeedsDisplay]` *------------* *------------* | | | | | 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][wwdc2012ui] by [Andy Matuschak][amtwitter] (video requires an ADC login). [wwdc2012ui]: https://developer.apple.com/videos/wwdc/2012/ [amtwitter]: http://twitter.com/andy_matuschak