Position and anchorPoint properties of CALayer
In iOS, UIView such as UIButton and UIImage can be displayed on the screen because there is a layer (CALayer) inside it. You can access this layer through the layer property of UIView:
@ property (nonatomic,readonly,retain) CALayer * layer
When the UIView needs to be displayed on the screen, the drawRect: method will be called to draw, and all the content will be drawn on its own layer. After the drawing is finished, the system will copy the layer on the screen, so the display of the UIView will be completed.
There are two confusing attributes in UIView, postion and anchorPoint (anchor point). Postion is used to set the position of CALayer in the parent layer, and anchorPoint determines which point on CALayer will be on the postion point. For example, the red × × layer should be added to the green × × layer.
(1) positon is (100100), anchorPoint is (0J0), and the effect is as follows
(2) positon is (100100), anchorPoint is (0.5), and the effect is as follows.
(3) positon is (100100), anchorPoint is (1). The effect is as follows.
(4) positon is (100100), anchorPoint is (1c0.5). The effect is as follows.