重寫prepareLayout方法
- 作用:在這個方法中做一些初始化操作
- 注意:一定要調(diào)用[super prepareLayout]方法
重寫layoutAttributesForElementsInRect方法
- 作用:
這個方法返回的是一個數(shù)組
這個數(shù)組中存放的都是UICollectionViewLayoutAttributes對象
UICollectionViewLayoutAttributes對象決定了cell的排布方式(frame)
重寫shouldInvalidateLayoutForBoundsChange方法
- 作用:
當(dāng)collectionView的顯示范圍發(fā)生改變的時候是否需要重新刷新布局 一旦重新刷新布局 就會重新調(diào)用下面的方法
1.layoutAttributesForElementsInRect 這個方法
2.prepareLayout
重寫targetContentOffsetForProposedContentOffset方法
- 作用:
這個方法的返回值 決定了collectionView停止?jié)L動時的偏移量 - 參數(shù):
proposedContentOffset 決定了 collectionView滾動停止時 最終的偏移量
velocity 滾動速率通過這個值可以了解滾動的方向