I was trying to learn the new layout transition effect in iOS7 collection view.
However, I am unable to get it to work at all. I have attached a screen shot description below.
I am aware that the same Collection View is used between Controllers when this Transition effect is in effect. But, why that collection view is not reloading when transition is happening. I even tried Reloading the collection view an that too failed.
There should be some simple point I should be missing. Help me please.
I have attached the source code below.
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
flowLayout.itemSize = CGSizeMake(75.0, 70.0);
ALCollectionViewNoXibController* controller = [[ALCollectionViewNoXibController alloc] initWithCollectionViewLayout:flowLayout];
controller.numberOfItems = _numberOfItems-1;
controller.transitionType = _transitionType;
if (_transitionType == kLayoutTransition) {
controller.useLayoutToLayoutNavigationTransitions = YES;
}
[self.navigationController pushViewController:controller animated:YES];
Project Code
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.