两个线性布局的方法

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

这个方法用来设置rect范围内所有的item的属性值

UICollectionViewLayoutAttributes:用来表示任意一个item属性

- (CGPoint)targetContentOffsetForProposedContentOffset:(CGPoint)proposedContentOffset withScrollingVelocity:(CGPoint)velocity

这个方法用来表示,当collectionview滚动的时候,本来停止滚动的时候,item最终停留的位置

@param proposedContentOffset 用来表示,本来停止滚动时候的偏移量位置

@param velocity              滚动的时候使用的力度

@return 返回最终停留的位置

- (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds

用来设置当现实的bounds(显示视图方位发生了变化)就会刷新布局,

重写调用layoutAttributesForElementsInRect,来设置每一属性的值,返回值设置为yes,才会有效果

原文地址:https://www.cnblogs.com/ritian/p/5149676.html