I. Introduction of Calayer
- In iOS, what you can see and touch is basically uiview, such as a button, a text label, a text input box, an icon, and so on, which are all UIView
- In fact, UIView can be displayed on the screen entirely because of a layer inside it
- When you create a UIView object, a layer (that is, the Calayer object) is automatically created inside UIView, which can be accessed through the Layer property of UIView.
@property (Nonatomic,readonly,retain) Calayer *layer;
- When UIView needs to be displayed on the screen, the DrawRect: method is called to draw, and all the content is drawn on its own layer, and after the drawing is finished, the layer is copied to the screen, so the display of the UIView is completed.
- In other words, the UIView itself does not have the function of the display, it is the inner layer of the display function
Second, the basic use of Calayer
Iii. attributes of Calayer
@property cgrect bounds;
- Location (default midpoint, determined by Anchorpoint)
@property cgpoint position;
- The anchor Point (x, y range is 0-1), which determines the meaning of the position
@property Cgpoint Anchorpoint;
- Background color (cgcolorref type)
@property Cgcolorref BackgroundColor;
@property Catransform3d Transform;
- Border color (cgcolorref type)
@property Cgcolorref bordercolor;
@property CGFloat borderWidth;
- Content (e.g. set as Picture cgimageref)
@property (retain) ID contents;
The introduction of Calayer has 2 very important properties: position and Anchorpoint
@property cgpoint position;
Used to set the position of the Calayer in the parent layer, with the upper-left corner of the parent layer as the origin (0, 0)
@property Cgpoint Anchorpoint;
Known as Anchor Point, Anchor Point
Determines which point of the calayer is in the position indicated by the position attribute
In its own upper left corner as the origin (0, 0)
Its x, y range is 0~1, the default value is (0.5, 0.5)
Iv. doubts about the Calayer
First of all
- Calayer is defined in the Quartzcore framework.
- Cgimageref, cgcolorref Two types of data are defined in the Coregraphics framework.
- Uicolor, uiimage are defined in the Uikit framework.
Secondly
- The Quartzcore framework and Coregraphics framework are available across platforms and can be used on both iOS and Mac OS x.
- But Uikit can only be used in iOS
In order to ensure portability, Quartzcore cannot use UIImage, Uicolor, can only use Cgimageref, Cgcolorref
Introduction of Ios-calayer