IOS---Auto layout

Source: Internet
Author: User

The development of automatic layout

1.frame: Calculate frame with code

The physical size of the IPHONE3GS \ iPhone4 \ iphone4s screen is the same ( No screen adaptation is required ), and an application at that time is either a horizontal screen or a vertical screen, There is no application that can simultaneously switch between the screen and the

2.autoresizing:

Autoresizing is the attribute of UIView, always exists, the use is relatively simple, but not autolayout as powerful. If your interface is simple and the required details are not so high, you can use autoresizing to automate the layout.

With the release of the ipad, the physical size of the screen has changed, and some applications are required to achieve a screen shift , so the control frame can not be written dead, need to screen adaptation.

The core idea of autoresizing is to set the child control's frame with reference to the parent container. No longer write dead frame, but reference .

Example: In the vertical screen there is a button to occupy the entire width of the screen, when switching to a horizontal screen will also occupy the width of the entire screen

3.Auto Layout:

    • Auto layout is an "auto lay-out" technique that is designed to layout the UI interface
    • Auto layout has been introduced since iOS 6, and since Xcode 4.5 has not been given a lot of publicity
    • Since iOS 7 (Xcode 5), the development efficiency of Auto layout has been greatly improved.
    • Apple also recommends that developers use auto layout as much as possible to layout the UI interface
    • Auto layout makes it easy to solve problems with screen adaptation

iOS has two big automatic layouts: autoresizing and AutoLayout (AutoLayout is new after IOS6)

With the release of IPhone5 \ IPhone5S and other Apple devices, different sizes of screens have become more and more, not only to be able to set relative positions based on the parent-child relationship of the control, but also to set the position according to the relationship between "any" control.

Because autoresizing can only set the relative relationship between the current control and the parent control, Autoresizing is powerless when it encounters a relationship between the sibling controls.

Example: In the vertical screen, there are two buttons at the bottom of the screen, the spacing of the two buttons is a fixed value (the width is not specified);

When switching to a horizontal screen, both buttons are also displayed at the bottom of the screen, and the spacing between the buttons is constant, and the buttons can be widened accordingly.

Using AutoLayout

4.Size Classes:

In IOS8, a new size classes feature has been added

Looking at time as a supplement, today's main content is "Auto Layout"

When IPhone6 is released, Apple devices have more screens (and more screens with different sizes), and Apple has introduced size Classes technology to make it easier to adapt to different screens.

Constraints set by AutoLayout, constraints are applied to various screens once added (that is, the same constraints are used under various screens)

With size Classes + Auto layout, you can set different constraints for different sizes of screens

    • Example: In the 3.5 inch screen, you want a button to appear close to the top of the screen, but when the screen becomes 5.5 inch, you want the button to appear in the center of the screen
    • Size classes Technology is the main solution to the problem: for different sizes of the screen , the Auto Layout to set different constraints.

    • Use note
    • Note: either through autoresizing or auto layout is only indirectly set up the control frame, so once the use of autoreszing or auto layout, do not set the frame directly, the person may create confusion "conflict ”。
    • Apple strongly recommends using auto layout, so when creating a new project, we have chosen to use auto layout by default, since autoresizing and auto layout are mutually exclusive and only one of them can be used. To use autoresizing, you must first disable auto Layout

IOS---Auto layout

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.