Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UICollectionView的骨架屏动画期间会执行sizeForItemAtIndexPath 代理方法,导致初始化骨架屏时设置的cellSize被覆盖 #175

Open
wv-y opened this issue Sep 27, 2021 · 7 comments

Comments

@wv-y
Copy link

wv-y commented Sep 27, 2021

New Issue Checklist

  • [] I have read the Documentation
  • [] I have searched for a similar issue in the project and found none

Issue Info

Info Value
Platform Name e.g. iOS
Platform Version e.g. 模拟器IOS13.7
TABAnimated Version 2.6.0
Xcode Version Xcode12.5

Issue Description and Steps

懒加载中设置骨架屏

// 设置骨架屏
        _collectionV.tabAnimated = [TABCollectionAnimated animatedWithCellClass:[MyCell class] cellSize:CGSizeMake(Screen_Width, 171) animatedCount:5];
        _collectionV.tabAnimated.animatedCount = 5;
        _collectionV.tabAnimated.superAnimationType = TABViewSuperAnimationTypeOnlySkeleton;
        _collectionV.tabAnimated.filterSubViewSize = CGSizeMake(30, 15);
        
        _collectionV.tabAnimated.adjustWithClassBlock = ^(TABComponentManager * _Nonnull manager, Class  _Nullable __unsafe_unretained targetClass) {
            if (targetClass == MyCell.class) {
                manager.animationsWithIndexs(1, 18, 19, 20, 21, 23, 26).remove();
                manager.animation(3).reducedHeight(-5);
                ...
            }
        };
        [self.view addSubview:_collectionV];

页面开启,加载骨架屏时就执行方法:

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    ...
   // 需要在此处重新设置骨架屏cell的
    else if (self.collectionV.tabAnimated.isAnimating) {
        size = CGSizeMake(WKC_AppScreenWidth, 170);
    }
    return size;
}

在为UItableView设置骨架屏期间不会执行- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath, 所以初始化设置的cellHeight不会被覆盖。

@tigerAndBull
Copy link
Owner

看起来没有问题,去TABCollectionAnimated中的sizeForItemAtIndexPath方法里,打个断点调试一下

@wv-y
Copy link
Author

wv-y commented Sep 27, 2021

看起来没有问题,去TABCollectionAnimated中的sizeForItemAtIndexPath方法里,打个断点调试一下

感谢回复,我再调试看看,请问怎么加微信群,二维码过期了,有问题可以方便交流😂

@wv-y
Copy link
Author

wv-y commented Sep 27, 2021

@tigerAndBull 作者大佬,你好
使用以下写法,在第一次进入页面时骨架屏没有cell1的视图,后续再进入则都可以正常展示,不会再复现这个问题,打出来的包在真机运行也是一样的问题。
两个cell的init方法中我都有添加试图。
真机是iPhone 12, IOS14.7

 NSArray *cellClassArray = @[[Cell1 class],        [Cell2 class]];
        NSArray *sizeArray = @[@(CGSizeMake(Screen_Width, 200)), @(CGSizeMake(Screen_Width, 90))];
        
        TABCollectionAnimated *tabAnimated = [TABCollectionAnimated animatedWithCellClassArray:cellClassArray cellSizeArray:sizeArray animatedCountArray:@[@(1),@(1)]];
        
        tabAnimated.superAnimationType = TABViewSuperAnimationTypeShimmer;
        tabAnimated.animatedColor = WKC_HEXRGBCOLOR(0xf6f6f6);
        
        tabAnimated.adjustWithClassBlock = ^(TABComponentManager * _Nonnull manager, Class  _Nullable __unsafe_unretained targetClass) {
            if (targetClass == [cell1 class]) {
                manager.animation(0).reducedHeight_horizontal(-Screen_Width).reducedWidth_vertical(-Screen_Width);
            }
            if (targetClass == [cell2 class]) {
                manager.animation(0).width(100);
                manager.animation(1).width(100).reducedHeight_horizontal(8);
            }
        };
        _collectionV.tabAnimated = tabAnimated;

Simulator Screen Shot - iPhone 8 - 2021-09-27 at 18 03 03
Simulator Screen Shot - iPhone 8 - 2021-09-27 at 18 03 10

@tigerAndBull
Copy link
Owner

看起来没有问题,去TABCollectionAnimated中的sizeForItemAtIndexPath方法里,打个断点调试一下

感谢回复,我再调试看看,请问怎么加微信群,二维码过期了,有问题可以方便交流😂

用2.6.2试试,不行加wx: _tigerAndBull

@wv-y
Copy link
Author

wv-y commented Sep 30, 2021

看起来没有问题,去TABCollectionAnimated中的sizeForItemAtIndexPath方法里,打个断点调试一下

感谢回复,我再调试看看,请问怎么加微信群,二维码过期了,有问题可以方便交流😂

用2.6.2试试,不行加wx: _tigerAndBull
感谢回复,经过排查发现,这些问题是因为,项目中collectionView的layout是复写UICollectionViewFlowLayout的子类,2.6.0和2.6.2表现一致,直接使用UICollectionViewFlowLayout是没有问题的。

@tigerAndBull
Copy link
Owner

cellSize和cellHeight都有两种形态,一种是属性,一种是通过代理获取。

看起来没有问题,去TABCollectionAnimated中的sizeForItemAtIndexPath方法里,打个断点调试一下

感谢回复,我再调试看看,请问怎么加微信群,二维码过期了,有问题可以方便交流😂

用2.6.2试试,不行加wx: _tigerAndBull
感谢回复,经过排查发现,这些问题是因为,项目中collectionView的layout是复写UICollectionViewFlowLayout的子类,2.6.0和2.6.2表现一致,直接使用UICollectionViewFlowLayout是没有问题的。

重写的目的是什么,可能是重写后某些生命周期变化了,如果要继续追踪的话,需要提供重写了什么

@wv-y
Copy link
Author

wv-y commented Oct 23, 2021

cellSize和cellHeight都有两种形态,一种是属性,一种是通过代理获取。

感谢回复,经过排查发现,这些问题是因为,项目中collectionView的layout是复写UICollectionViewFlowLayout的子类,2.6.0和2.6.2表现一致,直接使用UICollectionViewFlowLayout是没有问题的。

重写的目的是什么,可能是重写后某些生命周期变化了,如果要继续追踪的话,需要提供重写了什么

重写是为了实现多列瀑布流,采用的layout是这个
https://www.jianshu.com/p/ca806664c58a
除了加了些容错,核心的东西是一样的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants