美文网首页
如何实现瀑布流,流水局

如何实现瀑布流,流水局

作者: 司夜 | 来源:发表于2016-07-28 15:18 被阅读26次

1.使用UIcollectionview

2.使用自定义的FlowLayout

3.需要在layoutAttributesForElemetsInRect中设置自定义的布局(item的frame)

4.在preparelayout中计算布局

5.遍历数据内容,根据索引取出相应的attributes(使用layoutAttributesForCellWithIndexPath),根据九宫格算法设置布局。

细节1:实时布局,重写shouldinvalidatelayoutforboundschange(bounds改变重新布局,scrollview的contentoffset>bounds)

细节2:计算设置item size (保证内容显示完整,UIcollectionview的contentsize是根据itemsize计算的),根据列最大高度/对应列数量求出最大高度累加得到

细节3:追加item到最短列,避免比不参差不齐。

相关文章

网友评论

      本文标题:如何实现瀑布流,流水局

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