Fast Automation Adapter for iphone X

Source: Internet
Author: User

Turn from: http://www.code4app.com/blog-822717-1471.html


For the iphone x adaptation, the main work to be done is to match the upper and lower unsafe areas.

In iOS development, there are two ways of Xib and code editing for layout. Both of these methods support absolute layout and AutoLayout two kinds.

Next, we'll explain how to automate the iphone x from Xib, code editing, absolute layout, and AutoLayout several layouts.

Xib layout

The absolute layout of the xib is not flexible, and if you want to change the view frame by a specific factor, you need to implement it through the property index. So this is only for Xib's AutoLayout to explain.

First XCode9 's Xib provides us with the safearealayout option, which does not support previous versions of IOS9.

Safearealayout

Then we need to constrain the view to the bottom or the top of the security zone to achieve the desired effect, but the constraint value is not fixed, you also need to balance the non-iphone x models.

Then you can find the solution from the following points:

First of all, our layout files are as follows:

The three identical labels are located at the bottom of the controller root view

Constraint file

First of all, if you are making a new page, then adding the constrain to margins property will help you when setting constraints, and the second label in the layout file is the layout using the margin property.

Constrain to margins

First of all, if you have a page that already exists, and you have set a constraint layout, you can find the corresponding constraint attribute, tick its relative to margin option, and point the constraint attribute to the Marigin.

Double-click it (╯>д<) ╯⁽˙³˙⁾

Constraint properties relative to margin portal

Tick It (╯>д<) ╯⁽˙³˙⁾

Relative to margin

Next we can see the effects of these three layouts

You can select the iphone x model to quickly view the results of the layout application by using View as: (certain model) in the bottom left corner of the layout view.

Layout effect

And the effect of the operation

Run effect

As you can see, the underlying constraints do not fit the unsecured zone at the bottom of the iphone x, and constrain to margins and relative to margin are perfectly suited to the iphone x.

Using Code layout

The layout of the code can still be AutoLayout, and it can be absolutely laid out by branching judgments.

AutoLayout

1. If you need to use the native API for AutoLayout layout, then you can use Nslayoutattributebottommargin as the bottom constraint enumeration value

1 2 Nslayoutconstraint *constraint = [Nslayoutconstraint constraintWithItem:self.leftLabel >attribute: Nslayoutattributebottommargin relatedby:nslayoutrelationequal ToItem:self.rightLabel >attribute: Nslayoutattributebottom multiplier:1 constant:0]; [Self.view Addconstraint:constraint];

2. If your AutoLayout is edited by masonry, then you only need to change the bottom constraint

In earlier versions of masonry

By:

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.