UICollectionView动画数据更改 [英] UICollectionView animate data change

查看:210
本文介绍了UICollectionView动画数据更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,我使用UICollectionView显示图标网格。

In my Project I use UICollectionView to display a grid of icons.

用户可以通过单击调用核心提取的分段控件来更改排序具有不同NSSortDescriptor的数据。

The user is able to change the ordering by clicking a segmented control which calling a fetch from core data with different 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只是弹出新数据。

The problem is that reloadData doesn't animate the change, UICollectionView just pops with the new data.

我应该跟踪更改前后单元格的indexPath,并使用[self.collectionView moveItemAtIndexPath:toIndexPath:]执行动画变化还是有更好的方法?

Should I keep track in which indexPath a cell was before and after change, and use [self.collectionView moveItemAtIndexPath: toIndexPath:] to perform the animation for the change or there is a better method ?

我没有太多进入子类化集合视图,所以任何帮助都会很棒......

I didn't get much into subclassing collectionViews so any help will be great...

谢谢,
比尔。

Thanks, Bill.

推荐答案

reloadData没有动画,也没有可靠的放入UIView动画块时这样做。它想要在UICollecitonView performBatchUpdates块中,所以尝试更类似的东西:

reloadData doesn't animate, nor does it reliabably do so when put in a UIView animation block. It wants to be in a UICollecitonView performBatchUpdates block, so try something more like:

[self.collectionView performBatchUpdates:^{
    [self.collectionView reloadData];
} completion:^(BOOL finished) {}];

这篇关于UICollectionView动画数据更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆