用Maonry如何实现UIScrollView
一,使用UIScrollView 与其他View 布局不同的地方在于,
ScrollView的高度/宽度不固定;
ScrollView的高度和宽度由其内容决定(即 Scroll View 的 contentSize 所决定);
内容的大小不能依赖于Scrollview;
二,网上使用Xib/StoryBoard的做法太多,自行百度就是。
如何使用Masonry实现UIScrollView,参考见:
Masonry介绍与使用实践:快速上手Autolayout
做法:1,新建一个container View, 其他子View都添加到container View上。
_bottomChannelsView = [[UIScrollView alloc]init];
[_bottomChannelsView setScrollEnabled:YES];
//_bottomChannelsView.scrollEnabled = YES;
[self addSubview:_bottomChannelsView]; container = [UIView new];
[_bottomChannelsView addSubview:container];
2,设置布局方法:
需要注意的是,container View的subView的constraints都必须依赖container,依赖scrollview和其他的view都不能达到想要的效果。
-(void)setBottomLayout
{
if (self.bottomView.count<=) {
return;
} WS(ws); [_bottomChannelsView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.and.right.and.bottom.mas_equalTo(ws);
make.top.mas_equalTo(_topChannelsView.mas_bottom);
// make.left.and.right.mas_equalTo(ws);
}]; [container mas_remakeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(_bottomChannelsView);
make.width.equalTo(_bottomChannelsView);
}]; [moreText mas_remakeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(container);
make.left.equalTo(container).with.offset();
make.top.equalTo(container.mas_top).with.offset();
make.height.mas_equalTo(@);
}]; //排底部channelItem CGFloat itemWidth =((kScreenWidth - )-*/)/; ChannelListItem *firstItem = (ChannelListItem *)self.bottomView[];
firstItem.hidden = NO;
[firstItem mas_remakeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(moreText.mas_bottom).with.offset();
make.left.equalTo(container.mas_left).with.offset();
make.width.equalTo(@(itemWidth));
make.height.equalTo(@);
//第一排离superview是15 vpadding
}]; ChannelListItem *lastItem = firstItem;
ChannelListItem *item ;
for (int i = ; i<self.bottomView.count; i++) {
item = (ChannelListItem *)self.bottomView[i]; [item mas_remakeConstraints:^(MASConstraintMaker *make) {
make.height.and.width.equalTo(firstItem); }]; if (i%==) {
[item mas_updateConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(container.mas_left).offset(); }]; firstItem = item;
}else
{
[item mas_updateConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(lastItem.mas_right).offset(); //约束冲突
make.top.mas_equalTo(firstItem);
}]; }
if(i<)
{
[item mas_updateConstraints:^(MASConstraintMaker *make) {
// make.top.equalTo(_topChannelsView.mas_top).offset(15); //第一排离superview是15 vpadding
make.top.equalTo(firstItem);
}];
}else if(i%==) {
[item mas_updateConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(lastItem.mas_bottom).offset(); //非第一排
// make.top.equalTo(firstItem.mas_top);
}]; }
else {
[item mas_updateConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(firstItem);
}];
}
lastItem = item;
} [container mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(item.mas_bottom).with.offset(20);
}]; }
效果差不多是这样:

不尽完美,欢迎指正。感谢!
用Maonry如何实现UIScrollView的更多相关文章
- 【原】Masonry+UIScrollView的使用注意事项
[原]Masonry+UIScrollView的使用注意事项 本文转载请注明出处 —— polobymulberry-博客园 1.问题描述 我想实现的使用在一个UIScrollView依次添加三个UI ...
- UIScrollView的封装
UIScrollView的封装 效果 特点 1.用法简单,尺寸大小,随意设置位置 2.可以有多个数据源的数据,可以定制不通的界面(如同上图,一个有文字,一个没有文字) 3.能够实现点击事件 用法 1. ...
- UI第十七节——UIScrollView
// 实例化一个ScrollView UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:[[UIScreen main ...
- UI控件(UIScrollView)
@implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; //创建一个scrollview UIScrollV ...
- UIScrollView的delaysContentTouches与canCencelContentTouches属性
UIScrollView有一个BOOL类型的tracking属性,用来返回用户是否已经触及内容并打算开始滚动,我们从这个属性开始探究UIScrollView的工作原理: 当手指触摸到UIScrollV ...
- iOS 视图:重绘与UIScrollView(内容根据iOS编程编写)
我们继续之前的 Hypnosister 应用,当用户开始触摸的时候,圆形的颜色会改变. 首先,在 JXHypnosisView 头文件中声明一个属性,用来表示圆形的颜色. #import " ...
- 学习笔记之-------UIScrollView 基本用法 代理使用
//contentSize.contentInset和contentOffset 是 scrollView三个基本的属性. // 滚动 self.ScrollView.contentSize =sel ...
- iOS UIScrollView的使用
一.为什么要用UIScrollView? 移动设备的屏幕大小是极其有限的,因此直接展示在用户眼前的内容也相当有限当展示的内容较多,超出一个屏幕时,用户可通过滚动手势来查看屏幕以外的内容普通的UIVie ...
- iOS之UIScrollView循环滚动
#import "ViewController.h" #define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width #d ...
随机推荐
- [转]iis7.5+win2008 出现 HTTP Error 503. The service is unavailable.
解决: 应用程序池启动32位应用程序 设置托管管道为集成 (仍然有问题) 试试以下方法: http://phpwind.me/1222.html 楼主 发表于: 2011-11-26 图片: ...
- paper 88:人脸检测和识别的Web服务API
本文汇总了全球范围内提供基于Web服务的人脸检测和识别的API,便于网络中快速部署和人脸相关的一些应用. 1:从How-old的火爆说起 最开始,网站的开发者只是给一个几百人的群发送email,请他们 ...
- 2016-9-6 批量给文件名的前面加上“igeek_高薪就业” 2、 利用FileInputStream和FileOutputStream复制文件
在此只列出典型题目,有的题目扫一眼就有代码的不去浪费时间了,想要完整题目的评论留邮箱,看到就发.持续更新中... 1.批量给文件名的前面加上“igeek_高薪就业” package com.work; ...
- 夺命雷公狗---微信开发17----自定义菜单的事件推送,响应菜单的CLICK
废话不多说,index.php 代码如下所示: <?php /** * wechat php test */ //define your token require_once "com ...
- ThinkPHP讲解(四)——视图
本次讲解主要以<ThinkPHP开发手册>中“模板”一章中讲解为主 在MainController.class.php中新建一个操作方法Test() namespace Home\Cont ...
- 在Debian下安装ibus输入法
sudo apt-get install ibus ibus-pinyin im-switch sudo apt-get install ibus-googlepinyin im-switch -s ...
- 如何把一个java工程打成一个jar包(转载)
1.jar包有入口(即有main()函数) 选中要打包的工程--->右键选择Export---->java----->Runnable java file----->next- ...
- 出现“不能执行已释放的Script代码”错误的原因及解决办法
很多web开发者或许都遇到过这样的问题,程序莫名奇怪出现“不能执行已释放Script的代码”,错误行1,列1.对于这种消息描述不着边,行列描述更是让人迷茫的js错误,相信是所有调试js程序的朋友们最郁 ...
- PANIC : Error configuring AvalonLogSystem :
ll /tpsys/weblogic/user_projects/domains/mall/velocity.log 有1.7版本的的,不用这个1.4的.1.4会有这个问题: PANIC : Erro ...
- hibernate核心接口,和扩展接口。回顾笔记,以前没记,现在补上,纯手工敲的。
hibernate核心接口: 所有的hibernate应用都会访问hibernate的5个核心接口 1,Configuration接口 Configuration用于配置并且根启动Hibernate. ...