Panda Pig • Patty original or translated works. Welcome reprint, Reprint please indicate the source.
If you feel that the writing is not good please more advice, if you feel good please support a lot of praise. Thank you! Hopy;)
The coordinate system of the cocoa layer has not been understood clearly, and now it is summed up:
The position of the 1:layer in the super layer is determined by the frame property, and the origin of the Bounds property is always (0,0), because bounds is relative to the layer itself.
2:layer also has a position property, which is the position of the anchor point in the super layer. It has a direct relationship to the anchor point, although it is not in a coordinate system, but they are coincident!position coordinate systems in their superlayer, The coordinate system of the anchor point is on the layer itself.
3: A magical feature is that although the anchor point is closely related to the position, the modification of the two will not have any effect on the value of the other! The effect is the value of origin in frame! One corollary: If you change the anchor point, The position of the layer in the Superlayer will also change, i.e. origin will change.
The online paragraph understands that because they are not in a coordinate system, they are not affected by each other, but at the same time they are interacting with each other (a bit of quantum mechanics bright;])
4: If the origin value in Layer.frame is modified directly, the effect will be position.
5: The following formula helps to understand:
position.x = frame.origin.x + anchorPoint.x * bounds.size.width; position.y = frame.origin.y + anchorPoint.y * bounds.size.height;
The location of origin in 6:mac and iOS is different:
A minimalist understanding of the cocoa middle layer (layers) coordinate system