A probe into the Autoresizingmask attribute of the 2:uiview of lattice and knowledge

Source: Internet
Author: User

The Autoresizingmask property of UIView is used to automatically adjust the position and size of the UIView instance in the parent control when the size of the parent control of a UIView instance changes. The Autoresizingmask property is an enumeration value whose enumeration members are as follows:

It adjusts by automatically changing the top, bottom, left, right, width, or height of the uiview. Here are a few scenarios to discuss this property, assuming that the parent control is Backgroundview and the child control is subview:

1. The Autoresizingmask property does not work when the Autoresizingmask property is not used or the value of the Autoresizingmask property is uiviewautoresizingnone . At this point, when the Backgroundview changes, Subview does not react (frame unchanged), such as:

2, when set Subview. autoresizingmask=uiautoresizingflexibleBottommargin or set Subview. Autoresizingmask=uiautoresizingflexibleRight margin, found the effect and not set the same;

3, when set Subview. Whenautoresizingmask=uiautoresizingflexible left margin, the effect is as follows:

4, when set Subview. When autoresizingmask=uiautoresizingflexibleTopmargin, the effect is as follows:

5. Then take a look at the combination of cases, multiple Autoresizingmask properties can be passed through the "|" combined to act together. Like when Subview. Autoresizingmask=uiautoresizingflexibleLeft Margin | When uiautoresizingflexibleTopmargin, the effect is as follows:

Can see Subview in constantly change left and top direction and Backgroundview distance, appeared subview has been closely followed by the effect of the lower right corner of the Backgroundview;

6, when Subview. Autoresizingmask=uiautoresizingflexibleTopMargin | uiautoresizingflexibleBottommargin, the effect is as follows:

It can be seen that the subview in the direction of the top and bottom constantly changing the distance between and Backgroundview, there has been the Subview has been centered in the vertical direction of the effect;

7. If you use 4 margin attributes at the same time, you will have the following effects:

Can see Subview in constantly change 4 directions and Backgroundview distance, appeared the Subview has been centered effect;

8, it can be concluded that: using the margin class enumeration members, subview corresponding direction of the edge will automatically adjust and backgroundview the corresponding edge distance, but the size of subview is unchanged. Therefore, in this process, the frame.origin of Subview may change, but the frame.size will not change;

9, next when Subview. Autoresizingmask=uiautoresizingflexibleWidth When the effect is as follows:

10, when Subview. When Autoresizingmask=uiautoresizingflexibleHeight , the effect is as follows:

11. This combination of two enumeration members using width and height is very common and has the effect of:

Can see, subview in constantly changing their size, keep 4 directions and Backgroundview distance unchanged, appeared the Subview has been centered and followed the effect of backgroundview change;

12, it can be concluded that: using the width and height of two enumeration members, Subview will be transformed by the size of the corresponding direction of the edge and the distance between the Backgroundview remain unchanged. That is, in this process, the frame.origin of Subview is not changed, and Frame.size will change;

13, we can also use the margin and width, height combination, when subview. Autoresizingmask=uiautoresizingflexibleWidth | UiautoresizingflexibleTopMargin | uiautoresizingflexibleBottommargin, the effect is as follows:

You can see that the Subview combines three properties, and it constantly changes its width to keep the left and right sides of the Backgroundview constant, while changing the upper and lower two directions (top, bottom) and the distance of the Backgroundview remain in the vertical direction of the center;

14, finally look at this situation, when the combination of left and width, the following effects appear:

We already know that left to let the margin of flexibility change, and width is to maintain the left and right margin unchanged, the two contradictory characteristics of the subview left margin of irregular changes, it is not recommended to use this combination.

15, through the above test, we can get the following conclusions:

(1), the characteristics of the margin class will change the corresponding edge and the parent control of the margin, do not change the size, that is, will affect the frame.origin, will not affect the frame.size;

(2), Width and Height properties will not change the margins of the corresponding edge and parent control, but will change the size, that is, will affect the frame.size, will not affect the frame.origin;

(3), a plurality of characteristics can be combined to use, joint action;

(4), overlapping characteristics do not use combination, there will be irregular effect.

A probe into the Autoresizingmask attribute of the 2:uiview of lattice and knowledge

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.