IOS Adaptation/autolayout Basics

Source: Internet
Author: User
<span id="Label3"></p><p><p>Fitting<br>History<br>iphone3gs, iphone4\4s: No screen adaptation The program in the first development is all written dead.<br>Autoresizing comes out after the IPad spins out<br>Iphone5\5c\5s<br>Compatible with a variety of different situations<br>System adaptation to iOS version IOS6 7 8 9<br>Screen fit iPhone3.5 4.0 4.7 5.5 IPad 7.9 9.7<br>Developing point-oriented Development<br>5s = 320 * 480<br>6 = 375 * 667<br>6p = 414 * 736<br>Autoresizing<br>autolayout, Sizeclass must be turned off to use autoresizing<br>In the past if the screen rotation would rewrite willrotatetointerfaceorientation on the set side frame<br>Layout:<br>Graphical interface layout<br>Outside of the 4 lines, solid line represents the distance is the position of the control placement, note that the 2 lines are generally selected<br>The internal 2 lines, which indicate whether the width is stretched proportionally. When you select a device width of 320, you run on a 375 device, and you set it to 80 proportionally to the 375 device.<br>Limitations: resolving the relationship of Parent-child controls and not resolving sibling controls</p></p><p><p> Layout in code: be sure to set autoresizing <br> @property (nonatomic) uiviewautoresizing autoresizingmask before adding controls; <br> Uiviewautoresizing <br> Uiviewautoresizingnone Nothing at all <br> Uiviewautoresizingflexibleleftmargin-> left not fixed, right fixed, The spacing stretches with the screen size <br> uiviewautoresizingflexiblerightmargin-> to the right, fixed on the left, and the spacing stretches with the screen size <br> Uiviewautoresizingflexibletopmargin-> top is not fixed, bottom fixed, spacing is stretched with screen size <br> Uiviewautoresizingflexiblebottommargin-> The bottom is not fixed, the top is fixed, the spacing is stretched with the screen size <br> uiviewautoresizingflexiblewidth-> width follows the width of the parent control automatically proportional stretch <br> uiviewautoresizingflexibleheight-> height follows the height of the parent control automatically scale-up <br> finds that if you set the spacing fixed, you select an enumeration property in the opposite direction, and the left pin is used uiviewautoresizingflexibletopmargin, He means the right is not fixed, so the left is fixed </p></p><p><p>AutoLayout<br>Xcode4 (6.0) appeared AutoLayout but not very fire, to Xcode5 (ios7.0) when it was widely watched<br>Reference: referential, setting constraints relative to the control<br>Constraints: referencing some of the constraints of that control<br>Graphical interface layout<br>Setting: align-add New Alignment constrains-> (alignment)<br><br>Horizontal Center in container-> horizontal Center<br>Vertical Center in Container-> Vertical Center<br>Setting: pin-add New constrains-> (determine size, Size)<br>The effect of the above 4 lines sets the distance between the parent control and the left and right<br>The width and height below set the Control's own size<br>Support Line Set constraints<br>Between parent and child controls<br>Leading space to Container margin-> leading space to Container distance from the left side of the parent control<br>Trailing space to Container margin = = Trailing space to container-> distance from the right edge of the parent control<br>Bottom Space to Container<br>Bottom space to container-> distance from the bottom of the parent control</p></p><p><p>Center horizontally in container-> is centered horizontally with the parent control<br>Center Vertical in Container-> Center vertically with parent control<br>Control between brothers<br>Horizontal spacing-> relative to sibling horizontal spacing<br>Vertical spacing-> relative to sibling vertical spacing</p></p><p><p>Top-> relative to sibling top margin<br>Center vertically-> Align relative to sibling vertical center<br>Baseline-> offset from top of UI control<br>Bottom-> relative to sibling bottom margin</p></p><p><p>Leading \ left-> relative to sibling left margin<br>Center horizontally-> Align relative to sibling horizontal center<br>Trailing \ right-> Relative to brother right margin</p></p><p><p>Equal widths-> relative to brother width<br>Equal heights-> relative to brother height<br>Aspect ratio-></p></p><p>Holding shift to select multiple-> press SHIFT to select multiple<br>Hold option for alternates-> option to replace (bad)<br>Code Setup constraints<br>Constraints added to WHO<br>If this constraint is only related to yourself, then add it to yourself<br>If the constraint itself is related to the parent control, it is added to the parent control<br>If this constraint is related to other controls, it is added to the controls on their public parents<br>Nslayoutconstraint *constraint = [nslayoutconstraint constraintwithitem:view1 attribute:attr1 relatedBy:relation Toitem:view2 attribute:attr2 Multiplier:multiplier constant:c];<br>View1: view to Constrain<br>Attr1: that attribute (x, y, width, height)<br>Nslayoutattributeleft-> Left<br>Nslayoutattributeright-> Right<br>Nslayoutattributetop-> on<br>Nslayoutattributebottom-> under<br>Nslayoutattributeleading-> Left<br>Nslayoutattributetrailing-> Right<br>Nslayoutattributewidth-> width<br>nslayoutattributeheight-> height<br>Nslayoutattributecenterx-> Center point X<br>Nslayoutattributecentery-> Center Point Y<br>Nslayoutattributebaseline-> Basic Line<br>Nslayoutattributelastbaseline-> with Nslayoutattributebaseline<br>Nslayoutattributefirstbaseline-> First basic line<br>IOS8 new Constraint<br>Nslayoutattributeleftmargin-> left Margin<br>nslayoutattributerightmargin-> Right Margin<br>nslayoutattributetopmargin-> Top Margin<br>Nslayoutattributebottommargin-> Bottom Margin<br>Nslayoutattributeleadingmargin-> left Margin<br>nslayoutattributetrailingmargin-> Right Margin<br>Nslayoutattributecenterxwithinmargins-> Center x margin<br>Nslayoutattributecenterywithinmargins-> Center y margin<br> <br>Nslayoutattributenotanattribute-> no margin<br>Relation: constraining relationships<br>Nslayoutrelationlessthanorequal <=<br>Nslayoutrelationequal = =<br>Nslayoutrelationgreaterthanorequal >=<br>View2: the referenced view<br>Attr2: referenced attribute (x, y, width, height)<br>Multiplier: Multiple relationships<br>C: Extra value, value outside of multiples<br> <br>VIEW1.ATTR1 relation (=/</>) VIEW2.ATTR2 * Multiplier (multiple) + C<br>Note: 1. Be sure to have a parent control before adding a constraint, otherwise you will report an Error.<br>Use constraints be sure to set this value to prevent the system from converting some of the autoresizingmask settings to AutoLayout<br>2. Self.view1.translatesAutoresizingMaskIntoConstraints = NO;</p><p><p>Visual format language-> VFL visual formatting language<br><br>Code<br>H:[control (width)]-margin[control (width)]<br>H:[control (>[email Protected])<br>V:[control (height)]-margin-[control (= = control)]<br>H:|-margin-[control (width)]-margin-[control (width)]-margin-|</p></p><p><p>Width: Wide<br>Height: High<br>Margin: pitch<br>H: Horizontal<br>V: Upright</p></p><p><p>Nsarray *array = [nslayoutconstraint CONSTRAINTSWITHVISUALFORMAT:VFL options:options metrics:metrics views:views];<br>[self.view1 addconstraints:array];<br>VFL:VFL statements<br>Options: set the direction of this constraint some control alignment, generally do not fill, if you fill in the Kniloptions<br>What does it mean to supplement its attributes later *******************************<br>Views:nsdictionaryofvariablebindings (control variable Name) real control variable corresponding to control in the VFL<br>Metrics nsdictionaryofvariablebindings (variable name):-> VFL Dynamic value</p></p><p><p><br>Masonry a autolayout-based third-party layout framework that greatly simplifies the AutoLayout code<br>Be sure to add to # "masonry"<br>No prefix is added to all places Mas_<br>#define Mas_shorthand<br>Mas_equalto basic data types do not need to be packaged (@100) and can be directly 100<br>#define Mas_shorthand_globals<br>Writing<br>Mas_ Opening<br>Mas_makeconstraints:<br>Make Create constraint<br>Mas_remakeconstraints: Re-create the constraint, delete the previous constraint, recreate the constraint<br>Mas_updateconstraints: modify constraints to overwrite previous constraints<br>Size:<br>Make.size.mas_equalTo (sizevalue). Multipliedby.offset (Value);<br>Make.width.mas_equalTo (Value);<br>Make.height.mas_equalTo (Value);</p></p><p><p>Boundary:<br>Make.left.mas_equalTo (Value);<br>Make.right.mas_equalTo (Value);<br>Make.leading.mas_equalTo (Value);<br>Make.trailing.mas_equalTo (Value);<br>Make.height.mas_equalTo (Value);<br>Make.edges.mas_equalTo (Value). insets (uiedgeinsetsmakevalue);</p></p><p><p>Center Point:<br>Make.center.mas_equalTo (centervalue);<br>Make.centerY.mas_equalTo (Value);<br>Make.centerX.mas_equalTo (Value);</p></p><p><p><br>Another way of writing, no packaging required<br>Make.centerX.equalTo (centerx);<br><br>Rule: make. properties. equalto/mas_equalto (reference property). multipliedby.offset (value)<br>Text description: Constraint attribute = Reference Property * value + offset value<br>Animation: must perform layoutifneeded refresh interface</p></p><p><p>Typically 1 controls are 4 constraints to determine their size and position, if multiple constraints are set to conflict<br>If there is a problem with a yellow (warning), red (error) problem constraint, then you must set the constraint to be successful without a problem calculation constraint</p></p><p><p>IOS Adaptation/autolayout Basics</p></p></span>

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.