UICollectionLayout布局 —— UIKit之学习UICollectionView记录二《流水布局》
重点知识
一、 加载collectionView注意事项
1.创建collectionView,有两种方式 :一种是xib和一种是纯代码;设置代理和数据源,注册cell,配置流水布局的属性,如上、下、左、右间距及行间距和列间距。

2. 创建CollectionViewCell,实现collectionView代理和数据源方法。
3. 设置每个cell的尺寸。
4.cell出现时显示动画
二、 流水布局思路分析
三、精华代码

1、布局一
//1.配置collectionView
self.automaticallyAdjustsScrollViewInsets = YES; //默认为No,
[self.view setBackgroundColor:[UIColor yellowColor]];
[self.collectionView registerNib:[UINib nibWithNibName:@"STRNearPeopleCell" bundle:nil] forCellWithReuseIdentifier:nearPeopleCell];
NSLog(@"%@",self.dataList);
[self.collectionView reloadData];
//2.显示动画及设置大小 和加载cell - (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath{
STRNearPeopleCell *hotcell = (STRNearPeopleCell *)cell;
[hotcell showAnamil]; }
//流水布局,系统UICollectionViewLayout.h
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
CGFloat outInset = self.collectionView.frame.size.width - 2 * kMargin;
NSInteger count = outInset / kItemSizeW;
NSInteger extraTotal = (NSInteger)(outInset - kMargin * (count - 1 )); CGFloat itemWH; if (extraTotal < count * kItemSizeW) { itemWH = extraTotal / count;
} else {
CGFloat extraWidth = extraTotal % kItemSizeW;
itemWH = kItemSizeW + extraWidth / count;
}
return CGSizeMake(itemWH, itemWH + 25);
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return self.dataList.count;
} // The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath:
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ STRNearPeopleCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:nearPeopleCell forIndexPath:indexPath];
return cell;
} //3.设置cell
- (void)awakeFromNib {
[super awakeFromNib];
// Initialization code
}
//此外是模拟数据,真实的话把注释取消掉,用来控制显示动画的。
- (void)showAnamil {
//x和y的最终值为1
// if (self.live.isShow) { //当有网络模型时,可以把isShow字段加进去
// return;
// }
self.layer.transform = CATransform3DMakeScale(0.1, 0.1, 1); [UIView animateWithDuration:1 animations:^{
self.layer.transform = CATransform3DMakeScale(1, 1, 1);
// self.live.show = YES; //如果已经显示过yes
}];
}
2、布局二
//定义每个UICollectionView 的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
return CGSizeMake(([UIScreen mainScreen].bounds.size.width-64) /3 ,([UIScreen mainScreen].bounds.size.width-64) /3);
} //定义每个UICollectionView 的 margin
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
return UIEdgeInsetsMake(20, 8, 20, 8);
}
UICollectionLayout布局 —— UIKit之学习UICollectionView记录二《流水布局》的更多相关文章
- 自定义UICollectionLayout布局 —— UIKit之学习UICollectionView记录一《瀑布流》
一.思路 思路一:比较每一行所有列的cell的高度,从上到下(也就是从第一行开始),从最短的开始计算,(记录下b的高度和索引,从开始计算,依次类推) 思路二:设置上.下.左.右间距和行间距.列间距及列 ...
- UICollectionView左对齐流水布局、右对齐流水布局
在平时使用的app中会经常碰到一些规格选择,筛选,标签等页面,这些页面的布局展示通常是左对齐流水布局.实现类似这样的左对齐流水布局有多种方式,如果选项少的话可以直接用UIButton实现.现在我们有一 ...
- 关于css布局的记录(二) --网格布局
网格布局 学习来自阮一峰老师的教程网格布局和网络上的一些资料的学习 1.定义: 顾名思义,网格布局是将页面按行(row)和列(column)划分成一个个网格来进行布局 使用方法:display:gri ...
- Lucene.net(4.8.0) 学习问题记录二: 分词器Analyzer中的TokenStream和AttributeSource
前言:目前自己在做使用Lucene.net和PanGu分词实现全文检索的工作,不过自己是把别人做好的项目进行迁移.因为项目整体要迁移到ASP.NET Core 2.0版本,而Lucene使用的版本是3 ...
- 《CSS网站布局实录》学习笔记(二)
第二章 XHTML与CSS基础 2.1 XHTML基础 XHTML是网页代码的核心内容,标准XHTML代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD ...
- UICollectionView的水平流水布局自定义layout
最近做合创共美的商城项目,遇到发货地址的不配送地区,是做一个弹出框,弹出框的布局是根据地名字数长短不齐的标签. 本来也可以用tableview来做的.只不过多建几个tableviewcell就可以了. ...
- Lucene.net(4.8.0) 学习问题记录五: JIEba分词和Lucene的结合,以及对分词器的思考
前言:目前自己在做使用Lucene.net和PanGu分词实现全文检索的工作,不过自己是把别人做好的项目进行迁移.因为项目整体要迁移到ASP.NET Core 2.0版本,而Lucene使用的版本是3 ...
- Activiti 学习笔记记录(二)
上一篇:Activiti 学习笔记记录 导读:对于工作流引擎的使用,我们都知道,需要一个业务事件,比如请假,它会去走一个流程(提交申请->领导审批---(批,不批)---->结束),Act ...
- Material Calendar View 学习记录(二)
Material Calendar View 学习记录(二) github link: material-calendarview; 在学习记录一中简单翻译了该开源项目的README.md文档.接下来 ...
随机推荐
- ASP.NET Core管道深度剖析(2):创建一个“迷你版”的管道来模拟真实管道请求处理流程
从<ASP.NET Core管道深度剖析(1):采用管道处理HTTP请求>我们知道ASP.NET Core请求处理管道由一个服务器和一组有序的中间件组成,所以从总体设计来讲是非常简单的,但 ...
- 梯度提升树(GBDT)原理小结
在集成学习之Adaboost算法原理小结中,我们对Boosting家族的Adaboost算法做了总结,本文就对Boosting家族中另一个重要的算法梯度提升树(Gradient Boosting De ...
- 5.JAVA之GUI编程窗体事件
我们回顾下第三篇时的内容: 在3.JAVA之GUI编程Frame窗口中窗体是无法直接关闭的,想要关闭须进程管理器结束进程方式关掉. 现在我们就来解决下这个问题. ******************* ...
- 【转】async & await 的前世今生
async 和 await 出现在C# 5.0之后,给并行编程带来了不少的方便,特别是当在MVC中的Action也变成async之后,有点开始什么都是async的味道了.但是这也给我们编程埋下了一些隐 ...
- Qt安装配置
Qt Creator: 下载: Qt 5.5.1 for Windows 32-bit(MinGW 4.9.2, 1.0 GB):http://download.qt.io/official_rele ...
- C#和Java中的Substring()
吐槽-使用清理软件整理电脑要注意,不要清理的"太狠",不然你会受伤的! C#中的Substring() 示例 实现代码 using System;using System.Coll ...
- SQL SERVER 竖表变成横表
现有数据如下: Sql: select a.MODELID, max( case a.PNAME when'计划开始' then a.PVALUE end) as RStart, max( case ...
- C# - 多线程 之 锁系统
lock 关键字, Monitor 监控器, using System.Threading: // 提供同步访问对象的机制. public static class Monitor { public ...
- 微软要如何击败Salesforce?Office365、Azure、Dynamics365 全面布局AI | 双语
微软在上月宣布组建自己的 AI 研究小组.该小组汇集了超过 5000 名计算机科学家和工程师,加上微软内部研究部门,将共同挖掘 AI 技术. 与此同时,亚马逊,Facebook,Google,IBM ...
- 【转】 iOS9.2-iOS9.3.3越狱插件清单
以下是iOS9.3.3越狱插件清单 原文地址:http://bbs.feng.com/read-htm-tid-10668605.html 序列 支持与否 插件名称 兼容版本 支持设备 1 是 20 ...