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

自定义布局--继承UICollectionViewFlowLay

作者: 七里田间的守望者 | 来源:发表于2017-04-15 16:45 被阅读53次

重写prepareLayout方法

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

重写layoutAttributesForElementsInRect方法

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

重写shouldInvalidateLayoutForBoundsChange方法

  • 作用:
    当collectionView的显示范围发生改变的时候是否需要重新刷新布局 一旦重新刷新布局 就会重新调用下面的方法
    1.layoutAttributesForElementsInRect 这个方法
    2.prepareLayout

重写targetContentOffsetForProposedContentOffset方法

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

相关文章

网友评论

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

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