How to use useLayoutToLayoutNavigationTransitions in UICollectionView?

夙愿已清 提交于 2019-12-03 20:31:48

The new flowLayout that you are loading is indeed being used. You can see it if for instance, you do flowLayout.itemSize = CGSizeMake(10.0*_numberOfItems, 10.0*_numberOfItems);

Your issue is that in order to make the transition work, iOS will change your datasource during the animated transition.

Try this:

Make your class a Navigation delegate:

@interface ALCollectionViewNoXibController ()<UINavigationControllerDelegate>

Then set the delegate of the navigation to the current controller, before pushing

self.navigationController.delegate = self;
[self.navigationController pushViewController:controller animated:YES];

Now you can add

- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {

   ALCollectionViewNoXibController *controller = (ALCollectionViewNoXibController *)viewController;
   navigationController.delegate = controller;
   controller.collectionView.dataSource = controller;
}

This simple example will break when you navigate back to the top controller, because the viewController received is not of ALCollectionViewNoXibController class. But you get the idea.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!