UICollectionView自定义布局笔记

自定义布局需要继承类UICollectionViewLayout,然后重写该类提供的一些方法:

1、- (void)prepareLayout; 准备layout,可以初始化一些参数,设置一些属性。

2、- (CGSize)collectionViewContentSize;返回collectionView的contentSize。

3、- (NSArray  *)layoutAttributesForElementsInRect:(CGRect)rect;   返回rect(可视范围)内所有cell对应的layoutAttribute。

4、 - (UICollectionViewLayoutAttributes)layoutAttributesForItemAtIndexPath:(NSIndexPath)indexPath;返回indexPath对应item的layoutAtture对象。

5、- (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds;当collectionView的大小发生改变时,是否重新刷新layout:

6、 - (CGPoint)targetContentOffsetForProposedContentOffset:(CGPoint)proposedContentOffset withScrollingVelocity:(CGPoint)velocity;当collectionView滚动停止的时候停在什么位置。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容