Beginning Auto Layout Tutorial in IOS 7:part 1

Source: Internet
Author: User

Can better end the screen orientation and compatible with iphone and ipad solutions.

IOS6 has a new technology auto layout to help solve this problem. Not only does this technology support the development of apps in different sizes, but you don't need to create nib files or storyboards for each language.

The problem with springs and struts

You are familiar with autosizing masks, which is known as "springs and struts" mode. Autosizing mask determines what happens to the view when the Superview size changes. For example, when a view has a variable width, if the superview becomes wider, he will also widen. If there is a fixed right spacing, the right spacing of the view is aligned with the right margin of the Superview.

Create a new project Strutsproblem, open main.storyboard, and remove the option to use AutoLayout in File Inspector . After removing the storyboard will use the old struts-and-springs mode.

Note: The Auto layout option is turned on by default for any new nib or storyboard file created using Xcode 4.5 or better. This feature is available in iOS 6 and later. If you want to create a IOS5-compatible app with the latest Xcode, you'll need to disable this auto layout option in each nib or storyboard file. By not selecting the Use AutoLayout check box.

Drag three different view to main storyboard.

Run on iPhone Retina 4-inch simulator . Turn into the following diagram:

In fact, what you expect is the following result:

The diagram parameter in the upper left corner is modified so that the view is fixed to the upper-left corner, and the horizontal and vertical dimensions of the view change when the Superview changes size.

Figure parameter Modification in the upper right corner

The diagram parameter changes below

After running again, the effect is as follows:

There is improvement but the padding inside margin is not right. The reason is that autosizing masks tells the views that when superview change size, they also want to change the size, but it does not explain how much change.

To solve these problems, you need to implement code in springs and struts mode. For example, you can change the size of the controls that need to be changed by Viewwilllayoutsubviews .

In the viewcontroller.m

Do not run the app first, you need to restore the autosizing masks for the previous three view settings, no one will conflict with the method above. But the different sizes of the iphone play a different effect, because the above thing for 4-inch iphone, if replaced by 3.5 will have a problem, because the above is also hard coding. You can also set the location by relative position, but it is very time-consuming if the UI is complex.

Beginning Auto Layout Tutorial in IOS 7:part 1

Related Article

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.