美文网首页日常收录
TABAnimated 瀑布流适配方案

TABAnimated 瀑布流适配方案

作者: tigerAndBull | 来源:发表于2020-12-25 19:50 被阅读0次

    TABAnimated 瀑布流适配方案

    前言

    最近有不少小伙伴,希望TABAnimated适配瀑布流。
    本文将说明瀑布流适配方案和使用方式

    适配原理

    瀑布流是一种自定义UICollectionViewLayout,计算规则是不需要TABAnimated所关心的。
    但是为了提供一套瀑布流机制,通常开发者会通过代理,给到使用方,比如高度,每行几个row。

    基本原理

    这里设计到两种策略选择。
    一种是瀑布流布局私有化,开发者需要使用TABAnimated内置的瀑布流计算方式。这个因为需要开发者修改源代码,所以没有考虑。
    第二种是开发者将瀑布流SEL传递给TABAnimated,TABAnimated切面管理动画时的瀑布流,不关心你们的瀑布流计算方式
    但是,这个方法存在弊端,需要开发者的瀑布流高度代理,参数严格按照瀑布流布局对象,视图下标,视图宽度,依次排列,不可缺少不可更换位置。
    命名可以随意。

    _collectionView.tabAnimated.waterLayoutHeightSel = @selector(waterFallLayout:heightForItemAtIndexPath:itemWidth:);
    

    如何使用

    使用animatedWaterFallLayoutWithCellClass初始化接口。
    传入class类型,高度列表和SEL

    CGFloat height = CardCollectionViewCell.cellSize.height+50;
    NSArray <NSNumber *> heightArray = @[@(height), @(height+20), @(height+20), @(height+20), @(height+20), @(height+20), @(height+20), @(height+20)];
    TABCollectionAnimated *tabAnimated = [TABCollectionAnimated animatedWaterFallLayoutWithCellClass:CardCollectionViewCell.class
                             heightArray:heightArray
                               heightSel:@selector(waterFallLayout:heightForItemAtIndex:itemWidth:)];
    

    注意

    demo中内置了瀑布流样例,样例使用了外部的瀑布流布局,框架内不提供该布局。

    相关文章

      网友评论

        本文标题:TABAnimated 瀑布流适配方案

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