IOS UIScrollView uses Autolayout and iosuiscrollview

Source: Internet
Author: User

IOS UIScrollView uses Autolayout and iosuiscrollview

During the iteration and update of recent projects, you need to add a button in the previously written interface using Autolayout. After adding the button, the iPhone 5 and iPhone 4 are not displayed completely. after encountering the problem, I naturally thought of using UIScrollView, and soon I created a UIScrollView full screen, which included all the previous controls in [self. change view addSubview: xxx] to [self. scrollView addSubview: xxx], click a run button with full confidence, and fail to slide ......

After re-adjusting the concept, we solved this problem. We created a UIScrollView first, which is correct, and then created a contrainerView for storage before being added to [self. view], add the contrainer to the scrollview, and adjust the position of the contrainerView.

Code:

// Create a scrollview UIScrollView * scrollView = [[UIScrollView alloc] initWithFrame: CGRectZero]; [self. view addSubview: scrollView]; [scrollView mas_makeConstraints: ^ (MASConstraintMaker * make) {make. edges. similar to (self. view) ;}]; // create a view where various view Controls are placed and added to the scrollview. UIView * contrainerView = [[UIView alloc] initWithFrame: CGRectZero]; [scrollView addSubview: contrainerView]; UIView * view1 = [[UIView alloc] initWithFrame: CGRectZero]; Parameters = [UIColor redColor]; [contrainerView addSubview: view1: ^ (MASConstraintMaker * make) {make. left. top. similar to (@ 20); make. right. similar to (@ (-20); // If the width is not specified, the view cannot show make. width. similar to (@ (self. view. frame. size. width-40); make. height. failed to (@ 200);}]; UIView * view2 = [[UIView alloc] initWithFrame: CGRectZero]; view2.backgroundColor = [UIColor greenColor]; [contrainerView addSubview: view2]; [view2 mas_makeConstraints: ^ (MASConstraintMaker * make) {make. left. similar to (@ 100); make. top. pointer to (view1.mas _ bottom ). offset (10); make. right. similar to (@ (-100); // If the width is not specified, the view cannot show make. width. similar to (@ (self. view. frame. size. width-200); make. height. failed to (@ 400);}]; UIView * view3 = [[UIView alloc] initWithFrame: CGRectZero]; view3.backgroundColor = [UIColor redColor]; [contrainerView addSubview: view3]; [view3 mas_makeConstraints: ^ (MASConstraintMaker * make) {make. left. similar to (@ 20); make. top. pointer to (view2.mas _ bottom ). offset (10); make. right. similar to (@ (-20); // If the width is not specified, the view cannot show make. width. similar to (@ (self. view. frame. size. width-40); make. height. pointer to (@ 200);}]; // the container's top position is determined based on the last view control [contrainerView mas_makeConstraints: ^ (MASConstraintMaker * make) {make. edges. rollback to (scrollView); make. bottom. pointer to (view3.mas _ bottom ). offset (20) ;}];

 

If you did not see this article in wb145230 blog,Click to view Original Text.

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.