UICollectionView UseLayoutToLayoutNavigationTransitions具有不同的数据源
我有两个UICollectionView
对象,都有不同的来源和委托。 我希望通过使用UseLayoutToLayoutNavigationTransitions实现转换的“照片应用程序”。
它不工作。 当我调用UseLayoutToLayoutNavigationTransitions
它会更改布局,但不会更改内容。
第一张照片是第一个收集视图。 一系列类别和其中包含的人。
第二张照片是我想要animation最终成为一个类别内的一系列人。
最后的照片是现在发生的事情。 分类只是重新排列。
看看http://www.objc.io/issue-12/collectionview-animations.html中的
在UICollectionViewController实例之间转换
部分。
它基本上告诉你,你将不得不通过实施导航控制器委托方法手动改变数据源和委托:
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated { if ([viewController isKindOfClass:[FJDetailViewController class]]) { FJDetailViewController *dvc = (FJDetailViewController*)viewController; dvc.collectionView.dataSource = dvc; dvc.collectionView.delegate = dvc; [dvc.collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:_selectedItem inSection:0] atScrollPosition:UICollectionViewScrollPositionCenteredVertically animated:NO]; } else if (viewController == self){ self.collectionView.dataSource = self; self.collectionView.delegate = self; } }
你的问题是在转换过程中iOS会改变数据源。 看到我对这个问题的答案如何在UICollectionView中使用useLayoutToLayoutNavigationTransitions?
您可以使用在此描述的相同模式:
- 使用
UseLayoutToLayoutNavigationTransitions
获取布局更改 - 观察转换完成的时间
- 将数据源设置为当前所需的数据源