IOS development-project knowledge sharing and experience accumulation (1), ios development

Source: Internet
Author: User

IOS development-project knowledge sharing and experience accumulation (1), ios development

Recently, when I was working on a project, I used Storyboard to adapt to the screen quickly. After adding constraints, I found a problem (this problem will be shown in common cases below ); there is no problem on a screen of 4.7 or even greater, such as (4.7 screen ):

However, if the button is smaller than 3.5 inch, the problem may occur. The main reason is that there are too many input boxes, resulting in a larger screen, such as (3.5 screen ):

After thinking about it, I decided to use ScrolleView. The ContentSize can be set to a greater value. In this way, there is not much impact on other screens, and I can also slide under the 3.5 inch screen; however, when adding a ScrollView under Storybord and adding constraints, it is found that it will not be executed according to your conjecture. After careful research, we have roughly understood the cause; this is due to the complex features of scrollview, such as contentSize and contentInsets. When talking about autolayout, Apple documents even come up with a special section;

So how to automatically layout the scrollview?

Solution: you can add a unique subview (View) to the ScrollView. The size is the same as that of ScrollView. Then, all the controls added to the ScrollView are added to the subview) above;

The procedure is as follows:

1. First, add a ScrollView in the View that comes with our Controller. Generally, the margin of the next View is determined by Leading, Trailing, Top, and Bottom space, I usually use the quickest way: Right-click the StoryBoard and drag the line between the View and SuperView to choose from. However, if you use this method for UIScrollView, it will overlap with the SuperView edge, that is, if the margin is set to 0, you will find that it cannot be aligned with SuperView.

The reason is that there is a default Margin, and the default Margin around UIScrollView is 16 (xcode6.0 );

Solution: Do not use shortcuts. In the lower-right corner of the StoryBoard, click the second Pin icon and remove the check box for "Constrain to margins" in the pop-up window, set the four margins on them to 0, as shown in:

2. Add a View on the ScrollView to become a subview of ScrollView. Click 2nd of the four buttons for setting constraints below and set the distance between the constraint and ScrollView to 0.0.0.0, as shown in:

3. An error will be reported at this time. You don't need to worry about it. Let's continue;

4. Click the first of the four buttons for setting constraints below. Select Horizontal Center in Container and check the boxes. (If you want to slide left and right, select Vertical Center in Container, at the same time, both the left and right sides are not selected );

5. Open the 2nd options of the four buttons below to set the constraint and set the desired size (for example, 700). (If you want to slide left and right, select Width, at the same time, you can set both the left and right) (this height is the ContentSize of Scroller after running );

6. After the settings are complete, you will find that the error is missing and there is only one yellow warning. This is because the Frame is not updated. Let's update the Frame;

7. You can add controls on the subview of the ScrollView. Remember that when setting constraints, they are relative to the parent View;

8. Run the program and find that the screen on screen 3.5 inch can be moved. The screen on screen 4.7 is the same as the original one:

The next article will continuously update related knowledge points;

Email: dingding3w@126.com

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.