美文网首页
自定义布局-继承UICollectionViewFlowLayo

自定义布局-继承UICollectionViewFlowLayo

作者: 相识虽浅似是经年_凉城 | 来源:发表于2016-06-16 19:29 被阅读111次

重写prepareLayout方法

  • 作用:在这个方法中做一些初始化操作
  • 注意:一定要调用[super prepareLayout];

重写layoutAttributesForElementsInRect:方法

  • 作用:
  • 这个方法的返回值是个数组
  • 这个数组中存放的都是UICollectionViewLayoutAttributes对象
  • UICollectionViewLayoutAttributes对象决定了cell的排序方式(frame等)

重写shouldInvalidateLayoutForBoundsChange:方法

  • 作用:如果放回YES,那么collectionView显示的布局放生改变时,就会重新刷新布局
  • 一旦重新刷新布局,就会重新调用下面的方法:
  • prepareLayout
  • layoutAttributesForElementsInRect:

重写targetContentOffsetForProposedContentOffset:withScrollingVelocity:方法

  • 作用:这个方法的返回值,就决定了collectionView停止滚动时的偏移量
  • 参数:
  • proposedContentOffset:原本情况下,collectionView停止滚动时最终的偏移量
  • velocity:滚动速率,通过这个参数可以了解滚动的方向

相关文章

网友评论

      本文标题:自定义布局-继承UICollectionViewFlowLayo

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