What is CALayer?

What is CALayer (as can be seen from the layer property in the UIView) and where will we use such a class?

+4
source share
2 answers

UIView is an aggregate class. It contains โ€œmaterialโ€ for the chain of event responders, material for processing the hierarchy of representations, etc., as well as information on what to draw on the display. CALayer UIView is just what you need to draw: image bits, scale, transform, animation properties, etc.

The Cocoa Touch interface is displayed by arranging layers ... views on top of the views on top of the window. CALayer is a layer in the composition stack that exits on top of some layers and potentially under other layers. (for example, the image in a button in a table cell in a split view, etc.)

If you want to do something special with something that draws or displays a view that is not specified in the classes of the UIView class, perhaps it will be possible to do something special by going directly to CALayer: perhaps sharing layers between views and / or images, drawing off-screen elements, custom animations, etc.

There is more explained in Apple CALayer class reference document

+16
source

UIView is built on CALayers. These are just classes that are visual content for UIViews. Just print the UIView using NSLog and verify that we can see its content level and frame. Use Core Graphics to work with CALayers, and UIView is a UIKit element. self.view.layer.backgroundColor = [UIColor redColor].CGColor;

0
source

All Articles