Ios UICollectionView重新加载数据,但视图闪烁
我有一个Ios UICollectionView重新加载数据,但视图闪烁,ios,objective-c,uicollectionview,Ios,Objective C,Uicollectionview,我有一个UICollectionView和一个自定义的UICollectionViewCell来显示我的内容,应该每秒刷新一次 我将调用reloadData方法来重新加载整个集合视图以满足我的需要 但是,但是,每次我重新加载数据时,我的集合视图单元格都会闪烁 看起来像下图。两秒钟我的应用程序。第一秒没问题。但第二,集合视图首先显示重用的单元(黄色区域),然后显示正确的单元(配置的单元)。看起来像是眨眼 这似乎是一个单元重用问题采集视图显示单元格,但未完全完成配置。我怎样才能修好它 Mycell
UICollectionView
和一个自定义的UICollectionViewCell
来显示我的内容,应该每秒刷新一次
我将调用reloadData
方法来重新加载整个集合视图以满足我的需要
但是,但是,每次我重新加载数据时,我的集合视图单元格都会闪烁
看起来像下图。两秒钟我的应用程序。第一秒没问题。但第二,集合视图首先显示重用的单元(黄色区域),然后显示正确的单元(配置的单元)。看起来像是眨眼
这似乎是一个单元重用问题<代码>采集视图显示单元格,但未完全完成配置。我怎样才能修好它
MycellForItemAtIndexPath:
方法:
- (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;
}
帮了我的忙。好吧,我找到了答案,虽然离这个问题太远了 不要使用
reloadData()
或reloadditems()
使用
collectionView.reloadSections(IndexSet(integer:yourSectionIndex))
。动画将顺利进行。您是否使用带有xib的自定义单元格?@pawan我的所有代码都在目标CDO中如果您调用[collectionView ReloadItemsInstandExpaths:@[indexPath1,…]
而不是reloadData
,它是否仍会闪烁?您为什么每秒刷新一次收集视图?如果设置[UIView SetAnimationEnabled:NO]
调用重新加载数据之前(在重新加载/显示周期结束后,您可能需要在代码中稍后将其设置回[UIView SetAnimationEnabled:YES])嘿!非常感谢你!:)你让我不用花更多时间在我的低薪小时工资兼职上。哈哈。@Glenposadas很高兴这能帮上忙。希望你能找到一份更好的工作。
self.collectionView.reloadItems(at: self.collectionView.indexPathsForVisibleItems)