A minimalist understanding of the cocoa middle layer (layers) coordinate system

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.