在我的项目中,我使用 UICollectionView 来显示图标网格。
用户可以通过单击一个分段控件来更改排序,该控件调用具有不同 NSSortDescriptor 的核心数据的提取。
数据量始终相同,只是在不同的部分/行中结束:
- (IBAction)sortSegmentedControlChanged:(id)sender {
_fetchedResultsController = nil;
_fetchedResultsController = [self newFetchResultsControllerForSort];
NSError *error;
if (![self.fetchedResultsController performFetch:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
}
[self.collectionView reloadData];
}
问题是 reloadData 没有动画变化,UICollectionView 只是弹出新数据。
我应该跟踪更改前后单元格在哪个 indexPath 中,并使用 [self.collectionView moveItemAtIndexPath: toIndexPath:] 执行更改动画,还是有更好的方法?
我对 collectionViews 的子类化了解不多,所以任何帮助都会很棒...
谢谢, 比尔。
最佳答案
在 -performBatchUpdates:
中包装 -reloadData
似乎不会导致单节 Collection View 动画化。
[self.collectionView performBatchUpdates:^{
[self.collectionView reloadData];
} completion:nil];
但是,这段代码有效:
[self.collectionView performBatchUpdates:^{
[self.collectionView reloadSections:[NSIndexSet indexSetWithIndex:0]];
} completion:nil];
关于ios - UICollectionView 动画数据变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13272315/