I am setting my UICollectionViewController
's useLayoutToLayoutNavigationTransitions
property to 'YES' in order to perform layout to layout transitions for -[UINavigationController pushViewController:animated:]
and popViewControllerAnimated:
. In addition, I have implemented pinch gesture-based interactive transitions.
Also, I have defined a custom UICollectionViewTransitionLayout
that behaves differently from the original behavior of UICollectionViewTransitionLayout
. I create an instance of my "CustomLayoutTransition" object and return it from -[UICollectionViewDelegate collectionView:transitionLayoutForOldLayout:newLayout:]
.
I am expecting two behaviors when I do this
CustomLayoutTransition
is used to perform custom layout-to-layout transitions
1) when interactive transition is triggered by pinch gesture, or
2) when I push/pop an instance of UICollectionViewController
, e.g., by calling [UINavigationController pushViewController:animated:]
My expectation #1 seems to be correct, but #2 isn't; It seems that when I do push/pop programmatically, the original, Apple-provided UICollectionViewTransitionLayout
is used instead of my custom transition layout.
Is it normal that UICollectionViewTransitionLayout
is used instead of my custom transition layout in this circumstance?
If this is normal behavior, is there a way to use the custom transition to perform layout-to-layout transitions when programmatically pushing/popping UICollectionViewController
?
This is more a workaround rather than a proper solution, but imagine you want to change the layout by using:
[self.collectionView setCollectionViewLayout:self.finalLayout animated:YES];
But you want to provide your own UICollectionViewTransitionLayout, you could replace the above line by:
[self.collectionView startInteractiveTransitionToCollectionViewLayout:self.finalLayout completion:nil];
[self.collectionView finishInteractiveTransition];
and the delegate method
- (UICollectionViewTransitionLayout*)collectionView:(UICollectionView *)collectionView transitionLayoutForOldLayout:(UICollectionViewLayout *)fromLayout newLayout:(UICollectionViewLayout *)toLayout
gets called as expected.
Again, I would expect the delegate method to be called without the need of triggering the transition in this odd way but it does not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With