Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS push style segue transition

I want to change the "slide from right to left" transition of my navigation view controller when it pushes another view controller. I found an option in the storyboard but it doesn't seem to work. The transition style is still the same. By clicking the destination view controller in the storyboard I found this, although it looks like the transitions are for the modal style segue :

transition

So, my question is, is it possible to make the push style segue transition to look differently ? And if so, how ?

like image 338
Teo Avatar asked Dec 06 '12 13:12

Teo


2 Answers

You can use CATransition within a custom Segue to achieve any kind of transition. Here is sample code.

-(void)perform {

__block UIViewController *sourceViewController = (UIViewController*)[self sourceViewController];
__block UIViewController *destinationController = (UIViewController*)[self destinationViewController];                    

CATransition* transition = [CATransition animation];
transition.duration = .25;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush; //kCATransitionMoveIn; //, kCATransitionPush, kCATransitionReveal, kCATransitionFade
transition.subtype = kCATransitionFromLeft; //kCATransitionFromLeft, kCATransitionFromRight, kCATransitionFromTop, kCATransitionFromBottom



[sourceViewController.navigationController.view.layer addAnimation:transition
                                            forKey:kCATransition];

[sourceViewController.navigationController pushViewController:destinationController animated:NO];    


}

You visit this link for more details http://blog.jambura.com/2012/07/05/custom-segue-animation-left-to-right-using-catransition/

like image 83
Zakir Hyder Avatar answered Oct 11 '22 15:10

Zakir Hyder


In order to have the push transition you need to be using a UINavigationController connecting your views. Those are all modal transition options for one off transitions.

By the same token, at least in storyboards you can't use anything other than push if your are already using a UINavigationController.

The easiest way I've found to get around this limitation is to do it in code and to wrap a push without animation wrapped in a UIView Animation or CAAnimation.

like image 20
Ryan Poolos Avatar answered Oct 11 '22 15:10

Ryan Poolos