iOS development-Using AutoLayout-based ScrollView

Source: Internet
Author: User

Problem Description:

When laying out ScrollView using the AutoLayout layout, if you want to do a nine gongge that can scroll vertically, like this:

Take a line, it must not be taken for granted to try to give a row of icons evenly arranged operation (specify padding, image size adaptive), your scrollview to the right and bottom of the constraint is not valid. Constrained the result is useless, and then the image of the intrinsic size constraints will dominate, the ScrollView horizontal direction also top out of the screen, so that the scrollview horizontal direction can also be scrolled.

Workaround:

The solution is not to use AutoLayout in the ScrollView image size adaptive operation, under the premise of specifying padding, we can get the screen width, and then calculate the size of each picture in the case of N column, and then directly with the constraints of the size of each picture, The picture will be arranged normally.

Reference Source:

Specifically, to determine the content view and scroll view top, bottom, leading, and trailing contstraints, this place may be more confusing, because Apple's use of these four constraints in scroll Change in view: It is no longer the basis for determining the content view size, but rather to help scroll the boundaries around Content view in view (or you can understand it as white) to determine the contentsize properties of scroll view.

How to automate the layout of ScrollView (AutoLayout) in From:xcode6

We know that Uiscrollview has a contentsize property that defines the size of the ScrollView scrollable content. When we used to write in plain code, we would assign a value to this property directly, and define its size. But under AutoLayout, Uiscrollview's contentsize is defined by the constraints of its content. Therefore, the constraints we set in ScrollView not only play the role of layout content, but also play a role in defining the ScrollView scrollable range.

From:scrollview and AutoLayout

iOS development-Using AutoLayout-based ScrollView

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.