Examples of automatic iOS layouts

Source: Internet
Author: User

example of automatic layout

Automatic layout makes it easy to automatically solve many complex layout problems without manual manipulation. By creating the right combination of constraints, you can create layouts that are traditionally difficult to manage, such as isometric views, adapting to changing direction or size, scrolling inside elements that affect the size of scrolling content, or scrolling the contents of a view inside an element without scrolling.

with auto-use scrolling view layout

When you create an application using automatic layout, scrolling view can provide a unique challenge. Scrolling content must be set to the correct size so that users can scroll through all available content, for example, if you need to lock a context view scrolling view, such as map size and legends, it is difficult to ensure that elements do not scroll with other content.

control the size of scrolling view content

The size within the content scrolling view depends on the constraints of its descendants.

set the size of a scrolling view
    1. Create a scrolling view.

    2. The UI element inside.

    3. Create constraints fully define the width and height of the scrolling view content.

You must make sure that you create the constraints within the scrolling view. For example, when you define constraints for a view without an intrinsic content size, you need more than just a leading constraint that must also create trailing edges, widths, and height limits. There cannot be any omission of constraints from the scrolling view of an advantage.

Create a scrolling view within a fixed view

you will find that you want to create an area within a scrolling view of the user to scroll through the contents of the scroll view. You use a separate view to complete this container .

lock A view in scroll view
    1. Creates a container view scrolling view.

    2. Creates a scrolling view in the container view and equals zero points with all edges.

    3. Creates and scrolls a view within a child view.

    4. Creates a constraint from a child view of a container view.

The following example uses the steps that appear in the previous task to position a text view within a scrolling view. In this example, the text view keeps the scroll view at the bottom, moving when the scrolling view content is not moved.

First, create a container view that will contain scrolling views. Sets the size of the container view equal to the size of the desired scroll view.

After you create a container view, you create a scrolling view and move the inner view of its container. Adjust the scrolling view so that all edges are abundant on the edge of the container view, by setting the distance to 0.

Creates a second view and scrolls it inside the view. In this example, a text view is placed in a scrolling view.

Creates a constraint from the Text view Container view after the text view. Create constraints, Anchor text view Container view (skip scrolling view) Anchor text view is relative to the container view, which ensures that scrolling views do not scroll through the text view.

Creating a constraint that spans multiple views at the view level is generally easy to control-drag from the View Interface Builder outline view of the container view.

In the constraint overlay that appears, set the required constraints for the view.

In this example, create constraints from the leader, backward, and bottom of the Text view Container view. The height of the text view is also limited.

The following two data shows in the iOS app simulator, in normal and landscape locations. Scrolling views at the bottom of the text view and restrictions do not move as a scrolling view of the move.

Spacing and Packaging

Automatic interval layout provides some technical advice and adjusts items according to their content. The following sections describe how to create a constraint so that the visible view is based on the direction of the device.

the idea of creating equal spacing

Lists several views based on the direction of the device, such as spacing, to create a visible view between the interval views. Setting these shims the correct constraint ensures that the visible view can maintain the interval based on the device orientation.

Proportion of space views
  1. Creates a visible view.

  2. Create interval View the number of visible views plus 1.

  3. Alternately place your point of view from an interval of view.

    Space two visible views, put all the views in the following pattern, from the left screen and move right:

    spacer1 |  view1 |  spacer2 |  view2 |  spacer3 .

  4. Limit the interval of view, their lengths are equal.

    Note: The height of the interval view can be any value , including 0  . However, you must create a constrained height of views-don without leaving the ambiguous height.

  5. Create a view container from the first GASKET primary constraint view.

  6. Create a view container that is behind the last interval constraint view.

  7. Creates an interval view between constraints and a visible view.

Note: When vertical spacing is in perspective, from the top of the screen, and the view below the front of each view. The height of the set interval is equal to the view.

The following example uses the steps in the previous task to explain how to position two views such as spacing. The interval view is an example of a comment, but is usually an empty background. First, create two views and put them on the storyboard.

Add three intervals to the left left side of the view, a view between the two views, one to the right. The interval views do not need the same size at this time, because their size will pass through the constraints.

The interval view creates the following constraints:

    • interval view 2 and shim view width constraint 3 equals between The width of the isolated view is 1.

    • limit interval View 1 is greater than or equal to the lowest The desired width.

    • Create a leading space container constraint from the interval view 1 to the container.

    • Create a horizontal spacing constraint from the interval view 1 -1. Setting this constraint is a less than or equal to the constraint priority of 1000.

    • Create a horizontal spacing constraint view from the interval 2 -Views 1 and 2. Setting these limits is one less than or equal to the constraint priority of 999.

    • Create a horizontal spacing constraint from the interval view 3 views 2. Setting this constraint is a less than or equal to the constraint priority of 1000.

    • Create a trailing space container constraint from the interval view 3 to the container.

These constraints create two visible views and three invisible views (interval view). These interval views automatically adjust the orientation of the appliance, maintaining the spacing of visible views, as shown in the following two figure:

animation changed by automatic layout

If you need full control of the animation by automatic layout changes, you must make your constraints programmatically change. The basic concept is the same iOS and Mac OS X, but there are some subtle differences.

In the iOS app, your code will resemble the following points:

[Containerview layoutifneeded]; Ensures that all pending layout operations has been completed
[UIView animatewithduration:1.0 animations:^{
     Make all constraint changes here
     [Containerview layoutifneeded]; Forces the layout of the subtree animation block and then captures all of the frame changes
}];

In OS X, use the following code when using layer-backed animations:

[Containterview layoutifneeded];
Nsanimationcontext runanimationgroup:^ (Nsanimationcontext *context) {
     [Context Setallowsimplicitanimation:yes];
     Make all constraint changes here
     [Containerview layoutifneeded];
}];

When you do not use layer-backed animations, animations must continue to use constrained animations:

[[constraint animator] setconstant:42];

Examples of automatic iOS layouts

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.