Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using a custom transition layout when doing layout-to-layout navigation transitions

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?

like image 559
JYC Avatar asked Nov 10 '13 15:11

JYC


1 Answers

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.

like image 83
jjramos Avatar answered Sep 29 '22 14:09

jjramos