views:

113

answers:

1

What is a CALayer (as seen in the layer property on a UIView) and where would we use such a class?

+4  A: 

A UIView is a aggregate class. It contains "stuff" for the event responder chain, stuff for handling the view hierarchy, etc., as well as stuff regarding what to draw on the display. The CALayer of a UIView is just the stuff regarding what to draw: the image bits, the scale, transform, animation properties, etc.

The Cocoa Touch UI is drawn by compositing layers... views on top of views on top of a window. A CALayer is a layer in the composition stack which goes on top of some layers, and potentially underneath other layers. (e.g. an image in a button in a table cell in a view in a split view, etc.)

If you want to do something special with what a view draws or displays that isn't provided in the stock UIView class methods, it might be possible to do that special something by going directly to the CALayer: maybe swapping layers between views and/or images, drawing stuff off-screen, custom animations, etc.

There's lots more explained in Apple CALayer Class Reference document

hotpaw2
thanks hotpaws...
KingofHeaven