最近项目在迭代更新的时候,需要在之前用Autolayout写的界面里添加一个button,添加完这个button后,iPhone5,iPhone4显示不全了.遇到整个问题后很自然就想到了用UIScrollView,很快就创建了一个占满全屏的UIScrollView,把之前所有的控件有[self.view addSubview:xxx]全部改成[self.scrollView addSubview:xxx],信心满满的点击了一个运行按钮,艹,居然滑动不了......

  重新调整了一下思路,解决了此问题,先创建一个UIScrollView没错,然后创建一个contrainerView用于存储之前添加在[self.view]上的控件,把contrainer再添加到scrollview上,最后调整contrainerView的位置即可.

  代码:

// 创建一个scrollview
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectZero];
[self.view addSubview:scrollView];
[scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.view);
}]; // 创建一个view,这个view里面放置各种view控件,并添加到scrollview上
UIView *contrainerView = [[UIView alloc] initWithFrame:CGRectZero];
[scrollView addSubview:contrainerView]; UIView *view1 = [[UIView alloc] initWithFrame:CGRectZero];
view1.backgroundColor = [UIColor redColor];
[contrainerView addSubview:view1];
[view1 mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.top.equalTo(@);
make.right.equalTo(@(-));
// 宽度不写view显示不出来
make.width.equalTo(@(self.view.frame.size.width - ));
make.height.equalTo(@);
}]; UIView *view2 = [[UIView alloc] initWithFrame:CGRectZero];
view2.backgroundColor = [UIColor greenColor];
[contrainerView addSubview:view2];
[view2 mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(@);
make.top.equalTo(view1.mas_bottom).offset();
make.right.equalTo(@(-));
// 宽度不写view显示不出来
make.width.equalTo(@(self.view.frame.size.width - ));
make.height.equalTo(@);
}]; UIView *view3 = [[UIView alloc] initWithFrame:CGRectZero];
view3.backgroundColor = [UIColor redColor];
[contrainerView addSubview:view3];
[view3 mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(@);
make.top.equalTo(view2.mas_bottom).offset();
make.right.equalTo(@(-));
// 宽度不写view显示不出来
make.width.equalTo(@(self.view.frame.size.width - ));
make.height.equalTo(@);
}]; // 容器的顶部位置基于最后一个view控制来确定
[contrainerView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(scrollView);
make.bottom.equalTo(view3.mas_bottom).offset();
}];

  如果你不是在wb145230博客园看到本文,请点击查看原文.

iOS UIScrollView使用Autolayout的更多相关文章

  1. iOS学习笔记——AutoLayout的约束

    iOS学习笔记——AutoLayout约束 之前在开发iOS app时一直以为苹果的布局是绝对布局,在IB中拖拉控件运行或者直接使用代码去调整控件都会发上一些不尽人意的结果,后来发现iOS在引入了Au ...

  2. IOS UIScrollView常用代理方法

    iOS UIScrollView代理方法有很多,从头文件中找出来学习一下 //只要滚动了就会触发 - (void)scrollViewDidScroll:(UIScrollView *)scrollV ...

  3. 【转】iOS学习之Autolayout(代码添加约束) -- 不错不错

    原文网址:http://www.cnblogs.com/HypeCheng/articles/4192154.html DECEMBER 07, 2013 学习资料 文章 Beginning Auto ...

  4. UIScrollview 与 Autolayout 的那点事

    原文  http://www.cocoachina.com/ios/20151221/14757.html 前言 自从写了 介绍Masonry 那篇文章以后 就一直有人对UIScrollView的那个 ...

  5. iOS学习之Autolayout

    转载自:http://vit0.com/blog/2013/12/07/iosxue-xi-zhi-autolayout/ 学习资料 文章 Beginning Auto Layout Tutorial ...

  6. UIScrollView在AutoLayout下的滚动问题

    使用Storyboard编写UI,设置支持AutoLayout. 在其中的一个场景上,添加一个UIScrollView,在对应的代码里增加 - (void)viewDidLoad { [super v ...

  7. 示例详解:UIScrollview 与 Autolayout 的那点事

    前言 自从写了介绍Masonry那篇文章以后 就一直有人对UIScrollView的那个例子不是很理解 UIView *container = [UIView new]; [scrollView ad ...

  8. IOS UIScrollView + UIButton 实现segemet页面和顶部标签页水平滚动效果

    很长一段时间没有写博客了,最近在学习iOS开发,看了不少的代码,自己用UIScrollView和UIButton实现了水平滚动的效果,有点类似于今日头条的主界面框架,效果如下: 代码如下: MyScr ...

  9. iOS - UIScrollView

    前言 NS_CLASS_AVAILABLE_IOS(2_0) @interface UIScrollView : UIView <NSCoding> @available(iOS 2.0, ...

随机推荐

  1. 【hdu 1864】最大报销额

    Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s) ...

  2. [React Router v4] Create Basic Routes with the React Router v4 BrowserRouter

    React Router 4 has several routers built in for different purposes. The primary one you will use for ...

  3. 【a802】最少转弯问题

    Time Limit: 10 second Memory Limit: 2 MB 问题描述 给出一张地图,这张地图被分为n*m(n,m<=100)个方块,任何一个方块不是平地就是高山.平地可以通 ...

  4. easyui样式及js导入顺序及刷新回车的问题

    在使用easyui时,需要导入样式表及其js文件,在导入时.不光要遵守jquery包在easyui包的前面,还需要把样式表放在js的前边 <link type="text/css&qu ...

  5. Graphics-Processing Architecture Based on Approximate Rendering

    BACKGROUND The present invention generally relates to the processing of graphics data, and particula ...

  6. 12个被滥用的Android应用程序权限

    Android应用程序须要权限才干正常运作,只是网络犯罪分子会将其用在个人私利上.来看看最常被要求的权限以及它们会怎样被滥用. .网络定位功能 这代表什么:同意应用程序通过网络定位(像是基地台或无线网 ...

  7. IO 字符流学习

    import java.awt.Frame; import java.io.*; public class filewriter { /** * @param args */ public stati ...

  8. c语言学习笔记(11)——枚举

    # include <stdio.h> enum WeekDay  //定义了一个数据类型(值只能写一下值) { MonDay, TuesDay, WednesDay, ThursDay, ...

  9. matplotlib tricks(关闭坐标刻度、坐标轴不可见)

    plt.gray():只有黑白两色,没有中间的渐进色 1. 关闭坐标刻度(plt 与 AxesSubplot) plt plt.xticks([]) plt.yticks([]) 关闭坐标轴: plt ...

  10. DDD实战1

    1.创建空白解决方案 2.创建Infrastructure解决方案文件夹 3.在Infrastructure解决方案文件夹下面 添加一个新的项目 这个项目是 .net core的类库项目,取名Util ...