Search code examples
iosipadios5

How can I make iOS use the right navigation transition?


I've got an app with a totally standard UINavigationController using the default transition that slides the new view controller in from right to left. When I hit the Back button, it slides the previous view controller in from left to right. This works fine on iPhone and iPad, in both orientations, in iOS 5.1 and iOS 6. It also works in portrait mode on iOS 5.0.

BUT, in landscape mode on iOS 5.0 it does not work. New view controllers correctly slide in from right to left, but when I hit Back, the old previous view controller slides in from top to bottom.

This is very disorienting and I can't imagine where the behavior is coming from. I'm doing a plain vanilla push and pop of the view controllers, and it works fine in all the other combinations of OS and device and orientation. So what's going on here, and how can I fix it?


Solution

  • Well, I think this is simply a bug in iOS 5, since fixed in 6. To work around it, I figured out how to apply the correct transition manually; I override PopViewControllerAnimated in a custom UINavigationController subclass, and do this:

    //make a custom transition that does (very close to 
    var transition = CATransition.CreateAnimation ();
    transition.Duration = 0.25f;
    transition.Type = CATransition.TransitionPush;
    transition.Subtype = CATransition.TransitionFromLeft;
    
    this.View.Layer.AddAnimation (transition, "slide");
    
    var ret = base.PopViewControllerAnimated (false);
    
    this.View.Layer.RemoveAnimation ( "slide");
    
    return ret;
    

    Note that I'm using C# and Xamarin.iOS, but that's unrelated to the underlying problem.