Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Apple souce

macrumors member
Original poster
Mar 15, 2012
60
16
Probably a noob question, but I am having trouble figuring out why does CALayer exist when every UIView can display itself via the drawRect method?

Also, does the end of the drawRect method make a CALayer??

Reading the big nerd ranch ios book and stuck on the beginning of the core animation layer chapter.
 

Reason077

macrumors 68040
Aug 14, 2007
3,626
3,662
Think of UIView as a wrapper around CALayer. Each UIView has one CALayer backing it. But a CALayer isn't necessarily associated with a UIView.
 

firewood

macrumors G3
Jul 29, 2003
8,109
1,345
Silicon Valley
Every UIView has a CALayer. It's what a drawRect draws into.

UIViews, which encapsulate a bunch of stuff, including a built-in CALayer and event responder (etc.), are usually easier to use than all the sub-parts individually.

But using CALayers directly has the advantage that you can draw, swap, change, and update them in background threads (not so with most UI objects), and thus not have to wait for a drawRect callback, nor slow down the responsiveness of the app's UI main run loop with any lengthly draw.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.