Workarounds for iOS automatic layout and non-automatic layout nesting

Source: Internet
Author: User

/ * Say a few words about AutoLayout
* When there are AutoLayout and autoresize child controls within a control, the parts to be fitted autoresize
* translatesautoresizingmaskintoconstraints default is to open the converted
The size of the AutoLayout view can be calculated using the following code under AutoResize
if (!contentview.translatesautoresizingmaskintoconstraints) {
[Contentview needsupdateconstraints];
[Contentview updateconstraints];
cgsize ss = [Contentview systemlayoutsizefittingsize:uilayoutfittingcompressedsize];

         }
In addition, if the AutoLayout view is inside the autoresize view and you need to configure a relative position, you can use the following code to set
[Autoresizeview removeconstraints:autoresizeview.constraints];//or just delete the configuration content-related

nsdictionary *dic = nsdictionaryofvariablebindings (AutoLayout);
nsstring *VFL = [NSString stringwithformat:@ "V:|-%f-[autolayout]", RECT.ORIGIN.Y];
Nsarray *ar = [nslayoutconstraint constraintswithvisualformat:vfl options:0 metrics:nil views:dic];
[Autoresizeview Addconstraints:ar];

VFL = [NSString stringwithformat:@ "|-%f-[autolayout]", rect.origin.x];
AR = [nslayoutconstraint constraintswithvisualformat:vfl options:0 metrics:nil views:dic];

[Autoresizeview Addconstraints:ar];
         */


There is another way to calculate outside, add a uiview shell to the AutoLayout view,systemlayoutsizefittingsize: calculate the size set to the shell, and put it on a non-AutoLayout supported view

Workarounds for iOS automatic layout and non-automatic layout nesting

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.