美文网首页
瀑布流效果, 支持垂直, 水平, 浮动效果, 支持collect

瀑布流效果, 支持垂直, 水平, 浮动效果, 支持collect

作者: 书包里的码农 | 来源:发表于2019-02-03 17:35 被阅读22次
引言:

瀑布流效果是商品展示效果中一个较难实现的样式, 接下来我们介绍一个支持垂直, 水平, 浮动效果的瀑布流, ZZLayout(包含在ZZTools中, github传送门).

效果展示
i垂直瀑布流 浮动瀑布流 水平瀑布流
功能简介

1.垂直瀑布流, 在对应的协议方法中传入列数(默认为3), 以及item的高即可实现.(宽度相同, 自适应)
2.水平瀑布流, 在对应的协议方法中传入列数(默认为3), 以及item的宽即可实现,(高度相同, 自适应)
3.浮动瀑布流, 类似淘宝SKU选择页面中的等间距, 不等宽, 自动换行的效果, 在对应的协议方法传入item的宽即可实现,(高度相同, 自适应)
4.支持区头, 区尾部, 并且支持UITableView的headerView效果, 支持各种间距, 如每个分区的内边距等.
5.支持cocoapods集成, 请使用: pod 'ZZTools'

用法简介

1.垂直瀑布流的使用方法, 具体请查看点击github传送门查看demo, 另外星星评价哦.

//根据枚举初始化layou, 确定你想要的浮动效果, 传入你的collectionView即可
ZZLayout *layout = [[ZZLayout alloc] initWith:ZZLayoutFlowTypeVertical delegate:self];

2.协议方法

//ZZLyout的流协议方法
- (CGFloat)layout:(ZZLayout *)collectionViewLayout heightForRowAtIndexPath:(NSIndexPath *)indexPath {//返回item的高
    return rand() % 100 + 60;
}

- (NSInteger)layout:(ZZLayout *)collectionViewLayout columnNumberAtSection:(NSInteger)section {//每个区有几列
    return section;//默认值为3, 第0个区传入0时其实是使用了默认值.
}

3.头文件简介
协议方法

@class ZZLayout;

@protocol ZZLayoutDelegate <NSObject>

@optional
/**cell的宽(垂直瀑布流时此协议方法无效, 根据columnNumber和各种间距自适应)*/
- (CGFloat)layout:(ZZLayout *)collectionViewLayout widthForRowAtIndexPath:(NSIndexPath *)indexPath;

/**cell的高(水平瀑布流是此协议方法无效, 根据columnNumber和各种间距自适应)*/
- (CGFloat)layout:(ZZLayout *)collectionViewLayout heightForRowAtIndexPath:(NSIndexPath *)indexPath;

/**每个区多少列(浮动瀑布流时时此协议方法无效)*/
- (NSInteger)layout:(ZZLayout *)collectionViewLayout columnNumberAtSection:(NSInteger )section;

/**每个区的边距(上左下右)*/
- (UIEdgeInsets)layout:(ZZLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section;

/**每个item行间距(如果为水平方向瀑布流, 这里则是左右间距)*/
- (NSInteger)layout:(ZZLayout *)collectionViewLayout lineSpacingForSectionAtIndex:(NSInteger)section;

/**每个item列间距(如果是水平方向瀑布流, 这里则是上下间距)*/
- (CGFloat)layout:(ZZLayout*)collectionViewLayout interitemSpacingForSectionAtIndex:(NSInteger)section;

/**header的size*/
- (CGSize)layout:(ZZLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section;

/**footer的size*/
- (CGSize)layout:(ZZLayout *)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section;

/**本区区头和上个区区尾的间距*/
- (CGFloat)layout:(ZZLayout*)collectionViewLayout spacingWithLastSectionForSectionAtIndex:(NSInteger)section;

@end

初始化

/**自定义初始化方法, 建议使用*/
- (instancetype)initWith:(ZZLayoutFlowType)flowType delegate:(id<ZZLayoutDelegate>)delegate;

/**传入回调的代理, 建议通过自定义协议方法传入*/
@property (nonatomic , weak) id<ZZLayoutDelegate> delegate;

/**layout的类型, 暂不支持横向*/
@property (nonatomic , assign) ZZLayoutFlowType scrollDirection;

关于我们:

好用的话, 记得留下你的小星星哦.
欢迎吐槽, qq邮箱: 1156858877@qq.com

相关文章

  • 瀑布流效果, 支持垂直, 水平, 浮动效果, 支持collect

    引言: 瀑布流效果是商品展示效果中一个较难实现的样式, 接下来我们介绍一个支持垂直, 水平, 浮动效果的瀑布流, ...

  • RecyclerView vs ListView

    区别:ListView 只能在垂直方向上进行滑动,RecyclerView 支持垂直,水平滑动,多行多列瀑布流等形...

  • css

    一、清除浮动 法1:使用用伪元素 法2:使用兄弟节点清除 未清除浮动效果: 清除浮动后效果: 二、盒子垂直水平居中...

  • Flutter - flutter toast工具类 - JhT

    jhtoast 支持的效果:文字,图文,加载中,水平垂直两种布局pub地址:https://pub.flutter...

  • iOS - 支持水平/垂直显示自动滚动的跑马灯控件 --- SK

    简述 SKAutoScrollLabel是一个同时支持水平/垂直两种类型的“跑马灯”效果的自动滚动UILabel。...

  • 2018-09-19 day23-css布局

    标准流和display 效果: 浮动 效果: 浮动(文字环绕) 清除浮动 效果: 定位position 效果: 盒...

  • bootstrap 表单布局的三种方式

    三种 垂直表单(默认) 内联表单 水平表单 垂直表单 效果 内联表单 效果 水平表单 效果 参考:https://...

  • 瀑布流布局 的学习

    1- 实现瀑布流布局效果 瀑布流效果瀑布流代码木桶布局效果木桶布局代码瀑布流布局 2- 实现一个新闻瀑布流新闻...

  • 瀑布流、木桶布局

    瀑布流 瀑布流效果代码 木桶布局 木桶布局效果(加载有点慢)代码

  • Slider - 轮播图

    简介: 用react开发的轮播图组件,支持淡入淡出、水平滚动、垂直滚动的无缝轮播效果。可自定义轮播内容。 API ...

网友评论

      本文标题:瀑布流效果, 支持垂直, 水平, 浮动效果, 支持collect

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