美文网首页
UICollectionView自定义布局笔记

UICollectionView自定义布局笔记

作者: 指尖上舞蹈 | 来源:发表于2016-11-07 09:39 被阅读14次

自定义布局需要继承类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滚动停止的时候停在什么位置。

相关文章

网友评论

      本文标题:UICollectionView自定义布局笔记

      本文链接:https://www.haomeiwen.com/subject/amonuttx.html