AutoresizingMask attribute failure in xib, autoresizingmask

Source: Internet
Author: User

AutoresizingMask attribute failure in xib, autoresizingmask

In ios development, the layoutSubviews function and autoresizingMask attributes are indispensable for the layout of UIView.

When the autoresizesSubviews of a superview is Yes, the system will automatically typeset the autoresizingMask type of the subview. The optional attributes of autoresizingMask include:

UIViewAutoresizingNone = 0,

UIViewAutoresizingFlexibleLeftMargin = 1 <0,

UIViewAutoresizingFlexibleWidth = 1 <1,

UIViewAutoresizingFlexibleRightMargin = 1 <2,

UIViewAutoresizingFlexibleTopMargin = 1 <3,

UIViewAutoresizingFlexibleHeight = 1 <4,

UIViewAutoresizingFlexibleBottomMargin = 1 <5

 

Because the horizontal and vertical transformations are the same, we take the more common vertical transformations in the iPhone as an example:

UIViewAutoresizingNone.

UIViewAutoresizingFlexibleHeight: The top margin remains unchanged, and the height of superview is the same as that of superview. For example, if superview increases by 100, it increases by 100.

UIViewAutoresizingFlexibleTopMargin: The height remains unchanged. The top margin is flexible and the bottom margin remains unchanged.

UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleHeight, from 100 to 200. If your own bottom margin is 50, the ratio of the superview changes after the unchanged bottom margin is removed: (100-50)/(200-50) = 50/150 = 1/3. Then, the top margin and height are three times higher.

UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleHeight | Accuracy. For example, the height of a superview changes from 100 to 200. Then the top margin, height, and bottom margin of the current user are also two times the original ones.

However, it is not clear when the layoutSubviews function will be called. It only knows that it will be called asynchronously when frame is set. The following articles summarize several scenarios:

  • Init does not cause layoutSubviews to be called (duh)
  • AddSubview causes layoutSubviews to be called on the view being added, the view it's being added to (target view), and all the subviews of the target view
  • SetFrame intelligently cballs layoutSubviews on the view having it's frame set only if the size parameter of the frame is different
  • Scrolling a UIScrollView causes layoutSubviews to be called on the scrollView, and it's superview
  • Rotating a device only calllayoutsubview on the parent view (the responding viewControllers primary view)
  • RemoveFromSuperview-layoutSubviews is called on superview only (not show in table)

For the setFrame clause, it was thought to pass self in layoutSubviews. frame re-sets a different frme. It will call layoutSubviews again, leading to an endless loop. After experiment, it is found that it has not been generated and the specific cause is unknown.

If autoresizingMask is set in subview, and layoutsubviews are rewritten in supview, And the subview is set to typeset, The autoresizingMask of subview will not work.

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.