瀑布流的简单实现

其实瀑布流就是把 UICollectionViewLayout 这个类写成自己需要的样式,所以我们首先要继承这个类

重写这个类里面的一些方法

1.完成布局信息的预处理

-(void)prepareLayout

2.返回collectionView的内容的尺寸

-(CGSize)collectionViewContentSize

3.当边界发生改变时,是否应该刷新布局。如果YES则在边界变化(一般是scroll到其他地方)时,将重新计算需要的布局信息。

-(BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds

4.返回对应于indexPath的位置的cell的布局属性

-(UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath

5.返回rect中的所有的元素的布局属性

-(NSArray<UICollectionViewLayoutAttributes *> *)layoutAttributesForElementsInRect:(CGRect)rect

效果图:

demo链接地址:http://pan.baidu.com/s/1jHgg2Js

原文地址:https://www.cnblogs.com/hxwj/p/5053557.html