简体   繁体   English

UICollectionView reloadData但查看闪烁

[英]UICollectionView reloadData But View Blinks

I have an UICollectionView and a custom UICollectionViewCell to display my content, which should be refreshed every second. 我有一个UICollectionView和一个自定义UICollectionViewCell来显示我的内容,应该每秒刷新一次。

I am going to invoke reloadData method to reload the whole collection view to fit my needs. 我将调用reloadData方法来重新加载整个集合视图以适合我的需求。

But, but, My collection view cell blinks every time I reload data. 但是,但是,每次重新加载数据时,我的收藏夹视图单元都会闪烁。

It seems like the image below. 如下图所示。 Two seconds of my app. 我的应用两秒钟。 The first second is OK. 第一个可以。 But second second, the collection view display reused cell first (yellow area) and then display the correct cell(configured cell) finally. 但是第二秒,收集视图首先显示重用的单元格(黄色区域),然后最后显示正确的单元格(配置的单元格)。 Which looks like a blink. 看起来像眨眼。

在此处输入图片说明

It seems like a cell-reuse issue. 似乎是单元重用问题。 CollectionView displays cells without completely finish configure it. CollectionView显示单元时,尚未完全完成配置。 How could I fix it? 我该如何解决?

My cellForItemAtIndexPath: method: 我的cellForItemAtIndexPath:方法:

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    YKDownloadAnimeCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:[YKDownloadAnimeCollectionCell description] forIndexPath:indexPath];

    YKAnimeDownloadTask *animeDownloadTask = [[YKVideoDownloadTaskManager shared] animeDownloadTasks][indexPath.row];
    [cell setUpWithDownloadAnime:animeDownloadTask editing:self.vc.isEditing];
    cell.delegate = self;

    if (self.vc.isEditing) {
        CABasicAnimation *imageViewAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
        imageViewAnimation.fromValue = @(-M_PI/64);
        imageViewAnimation.toValue = @(M_PI/128);
        imageViewAnimation.duration = 0.1;
        imageViewAnimation.repeatCount = NSUIntegerMax;
        imageViewAnimation.autoreverses = YES;
        [cell.coverImageView.layer addAnimation:imageViewAnimation forKey:@"SpringboardShake"];

        CABasicAnimation *deleteBtnAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
        deleteBtnAnimation.fromValue = @(-M_PI/32);
        deleteBtnAnimation.toValue = @(M_PI/32);
        deleteBtnAnimation.duration = 0.1;
        deleteBtnAnimation.repeatCount = NSUIntegerMax;
        deleteBtnAnimation.autoreverses = YES;
        [cell.deleteBtn.layer addAnimation:deleteBtnAnimation forKey:@"SpringboardShake1"];
    } else {
        [cell.coverImageView.layer removeAllAnimations];
        [cell.deleteBtn.layer removeAllAnimations];
    }

    return cell;
}
self.collectionView.reloadItems(at: self.collectionView.indexPathsForVisibleItems)

对我有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM