Storyboard under ScrollView How to add a constraint

Source: Internet
Author: User

This article was reproduced from: http://www.lanou3g.com/bbs/forum.php?mod=viewthread&tid=5193

After doing the project there is a registration page, in order to fit the screen to use the storyboard, add the constraint after running after the discovery of a problem. Under 4.0 or even bigger screen is no problem, such as (4.0 screen)


But put in a smaller 3.5-inch will be the problem, found the following button is missing, the main reason is that the input box too much, resulting in a more screen can not put more. (3.5) inch



Think of the next decision to use Scrolleview, contentsize can be set to 560. This does not have much impact on other screens, and can be slid on the 3.5 screen.
But when Storybord dragged through ScrollView and added constraints, he did not follow your guess. After consulting the information, I know the reason.
This is due to the ScrollView itself contentsize, contentinsets and other complex characteristics, Apple documents in the AutoLayout of the time even specifically to come up with a section to say
How to automatically lay out the ScrollView.

The solution can add a unique child view to ScrollView, the size and ScrollView, and then all the controls that were originally added to the ScrollView,
Are added above the child view.


The steps are as follows:
1. First add a ScrollView to our controller's view, click on the 2nd of the 4 buttons below to set the constraint, and the constraint sets the distance from the parent attempt (0,0,0,0) as shown.


2. Add a view above ScrollView to ScrollView, click the 2nd of the 4 buttons below to set the constraint, and set the distance for the constraint distance ScrollView (0.0.0.0) as shown.

3. This time will find an error, not nervous ~, do not care about it, we continue to go down.

4. Click on the first of the 4 buttons below to set the constraint, select Horizontal Center in Container, and tick the checkmark, (if you want to swipe left and right, select Vertical Center in Container, while achieving the left and right up and down is not selected)


5. Open the 2nd of the 4 buttons below to set the constraint again to the height setting you want 560. (If you want to swipe left and right, select Width, and all settings are left and right)
(This height is scroller after the run of the Contentsize)

6. After the setting is complete, the error is missing, only a yellow warning, this is due to frame no update, we have to update the next frame.


7. Next we can add controls to this ScrollView view view. When you set a constraint, it is relative to the parent's attempt to view it. Layout.
8. Run the program, found in the 3.5 screen can already slide, and on the 4.0 screen or the same as the original figure: Left 3.5, right 4.0


Report:
The view above is a fixed set of values. If you want a dynamic setting, you need to set the constraint of the height we just added to the property


a name, height; then rewrite-(void) The Updateviewconstraints method, which dynamically sets the Constant property of this constraint after calling super.



This way you will find that the amplitude of scrollview can not be the same after each run OH ~;

Storyboard under ScrollView How to add a constraint

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.