【发布时间】:2014-05-19 14:48:06
【问题描述】:
我有一个 UICollectionView 和一个自定义 UICollectionViewCell 来显示我的内容,这些内容应该每秒刷新一次。
我将调用reloadData 方法来重新加载整个集合视图以满足我的需要。
但是,但是,每次我重新加载数据时,我的集合视图单元格都会闪烁。
看起来像下面的图片。我的应用程序的两秒钟。第一秒没问题。但是第二秒,集合视图首先显示重用的单元格(黄色区域),然后最后显示正确的单元格(配置的单元格)。看起来像眨眼。
这似乎是一个单元重用问题。 CollectionView 显示未完全配置的单元格。我该如何解决?
我的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;
}
【问题讨论】:
-
您是否使用带有 xib 的自定义单元格?
-
@pawan 我所有的代码都在目标c中
-
如果你调用
[collectionView reloadItemsAtIndexPaths:@[indexPath1, ...]]而不是reloadData,它还会闪烁吗? -
你为什么要每秒刷新一次收藏视图?
-
如果在调用
reloadData之前设置[UIView setAnimationsEnabled:NO]会怎样? (在重新加载/显示周期结束后,您可能需要稍后在代码中将其设置回 [UIView setAnimationsEnabled:YES])。
标签: ios objective-c uicollectionview