1)头视图和尾部视图的添加
UICollectionReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"headerView" forIndexPath:indexPath];

UICollectionReusableView *footerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"footerView" forIndexPath:indexPath];

2)内嵌(需求就是UICollectionView没有像Tableview一样的TabHeaderView),想要制造一个

contentInset

3)没有注册
[_collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"headerView"];
[_collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"footerView"];
2.使用UICollectionView遇到的复用问题

1)头视图的使用
for (UIView *view in headerView.subviews) {
[view removeFromSuperview];
}

for (UIView *view in footerView.subviews) {
[view removeFromSuperview];
}

2)cell的复用

KnowledgeBasePopCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"KnowledgeBasePopCell" forIndexPath:indexPath];

3.使用UICollectionView不走代理的问题

1)item尺寸计算错误

2)禁止使用0.01这种尺寸

//每个item之间的间距
-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{

return 0.01;
}

//定义每个Section 的 margin
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{

return UIEdgeInsetsMake(0.01,0.01,0.01,0.01);
}

上述两个是不走-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

3)在window上添加view,view上添加UICollectionView,是不走-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{

使用各种手势冲突判断解决方法,但是都没有效果

是UICollectionViewCell视图?
是UICollectionView类?
都不能捕捉到点击事件

解决方法:
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{

if ([touch.view isDescendantOfView:self.collectionView]) {
return NO;
}
return YES;
}

4。使用UICollectionView组头也可以悬停

UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
//header
flowLayout.sectionHeadersPinToVisibleBounds = YES;
//footer
flowLayout.sectionFootersPinToVisibleBounds = YES;

问题:这仅在iOS9中才支持这种设置

by:ml

使用UICollectionView遇到的各种坑的更多相关文章

  1. 记一次UICollectionView中visibleCells的坑

    记一次UICollectionView中visibleCells的坑 项目的要求是这样的 其实也是一个轮播图,而已,所以依照轮播图的实现原理,这里觉得也很简单,还是利用UICollectionView ...

  2. UICollectionView 如何定制每个Cell的Size

    最新用UICollectionView遇到挺多坑,差点让我废寝忘食了,虽然UICollectionView 逼格比UITableView高,但是真正想定制起来,特别是刚开始是用,真麻痹的到处都是坑,弄 ...

  3. iOS - UICollectionView 瀑布流 添加表头视图的坑

    UICollectionView 瀑布流 添加表头视图的坑 首先是,需求加了个头视图在顶部,在collectionView中的头视图跟TableView的不一样,TableView的表头只要设置tab ...

  4. UICollectionView cellForItemAtIndexPath 方法不走

    在storyboard 中 UICollectionView cellForItemAtIndexPath not called 被坑了好久,各种问题点查找,终于解决了 解决办法: self.auto ...

  5. 手把手教你使用UICollectionView写公司的项目

    在很多app中都有这样通用的页面,一直没有机会使用UICollectionView,只是简单的看过他的使用方法.今天公司美工出图,使用了他,并且遇到了好多的坑.记录一下过程,不确定使用的方法是不是最优 ...

  6. iOS 之UICollectionView 开发步骤 之 OC

    说起来容易做起来难. 那么我就不说了,来做吧.这就是我的style. 鉴于现在的主流还是OC,那么示例程序还用OC来写,后续补写Swift程序,这里先占个坑. 废话不多说,下面开发步骤来了: 1. 创 ...

  7. ios 适配iOS11&iPhoneX的一些坑

    前阵子项目开发忙成狗,就一直没做iOS11的适配,直到XcodeGM版发布后,我胸有成竹的在iPhoneX上跑起项目,整个人都凉透了...下面总结一下我遇到的坑,不是很全面,日后补充. 导航栏 导航栏 ...

  8. 关于collectionview布局的坑

    不知道写了多少次collectionview,步了很多坑,现在看来虽然达到了自己想要的结果,却不知道其中所以然.还是总结一下,免得再走弯路: 场景是这样的,我要定制一个显示选择图片的排列,想要实现横向 ...

  9. Xcode11.1 踩坑备忘录

    Xcode11.1 踩坑备忘录(mac系统10.15) 1 .环信ChatDemo2.0报错 这是环信ChatDemo2.0报错 NSInteger numberOfBeforeSection = [ ...

随机推荐

  1. 3分钟快速了解FastDFS

    1.介绍 FastDFS是一个C语言写的阿里开源的分布式文件存储服务器主要由两部分组成:1.Tracker server ——————主要负责调度和追踪Storage状态(调度服务器),默认监听端口: ...

  2. RGB色彩的计算机表示

    计算机显示模式[编辑] 24比特模式[编辑] 每像素24位(比特s per pixel,bpp)编码的RGB值:使用三个8位无符号整数(0到255)表示红色.绿色和蓝色的强度.这是当前主流的标准表示方 ...

  3. 动态规划:HDU1003-Max Sum(最大子序列和)

    Max Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Su ...

  4. Java面向对象---抽象类与接口

    final关键字 1.final关键字在java中被称为完结器,表示最终的意思: 2.final能声明类.方法.属性: 3.使用final声明的类不能被继承,使用final声明的方法不能被重写,使用f ...

  5. poj2955:Brackets

    Brackets Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8716   Accepted: 4660 Descript ...

  6. TCP/IP网络编程之多线程服务端的实现(一)

    为什么引入线程 为了实现服务端并发处理客户端请求,我们介绍了多进程模型.select和epoll,这三种办法各有优缺点.创建(复制)进程的工作本身会给操作系统带来相当沉重的负担.而且,每个进程有独立的 ...

  7. mac攻略(九) -- ssh工具secureCRT

    mac ssh 客户端 : 本身mac直接使用终端来ssh连接就很方便,但是使用过程中随着远程服务器的增多和zsh和远程服务器编码不同产生了乱码,决定安装一款ssh终端软件,以下方法亲测可用,感谢提供 ...

  8. leetcode 【 Partition List 】python 实现

    题目: Given a linked list and a value x, partition it such that all nodes less than x come before node ...

  9. Ubuntu18.04安装docker、docker-compose、

    Ubuntu18.04下Docker CE安装 Docker版本分为两个:Docker Community Edition (CE)和 Docker Enterprise Edition (EE).D ...

  10. Python3.0-3.6的版本变化

    Table of Contents Python3.0 简单的变化 语法的变化 新语法 改动的语法 剩下的变化 Python3.1 Python3.2 Python3.3 Python3.4 Pyth ...