iOS 7 added slide to the right to pop a view controller off the stack. Is it possible to add it back by sliding left?

ios, ios7, objective-c, uinavigationcontroller

Solution

The options depend upon the iOS versions you're trying to support.

In iOS 7+, you can use custom view controller transitions and implement interactive view controller transitions. For a conceptual description, see WWDC 2013 video Custom Transitions Using View Controllers. The basic process is:

Create an animation controller that defines what the animation is to be. The animation controller is an object that conforms to `UIViewControllerAnimatedTransitioning`. (Note, it might seem odd to have to define a custom animation controller for something as standard as a push animation, but below you'll see we want a gesture recognizer to interface with an interaction controller, but you cannot define a custom interaction controller if you don't also define a custom animation controller.)

Instantiate an interaction controller. You can create your own interaction controller class that conforms to `UIViewControllerInteractiveTransitioning`, but it's easiest to simply instantiate a`UIPercentDrivenInteractiveTransition` object.

Now that you have the interaction controller, you can link a gesture recognizer (e.g. a `UIScreenEdgePanGestureRecognizer`), to it. The gesture recognizer will call calling the interaction controller's `updateInteractiveTransition` to specify the progress of the animation as it corresponds to the continuous gesture.

Clearly, if you're going to recognize a swipe from the right edge as a "push" to a particular scene, then you'll have keep track of what that "next" scene is going to be. Sometimes you'll have a predefined series of view controllers. Sometimes you'll just keep an stack of view controllers that you previously popped from so that you can swipe from the right to push them back on. It just depends upon the desired UX.

The iOS 7 customer transitions provides incredible control in customizing both the animations and gestures linked to the interactive transition. But it takes a little work to do this right.

If you're just looking for an easier way to simply do slide transitions between a series of view controllers, you can use a `UIPageViewController`. In iOS 6 and later, you can employ a `transitionStyle` of `UIPageViewControllerTransitionStyleScroll`. (Unfortunately, in iOS 5, you only had the page curl transition.)

In iOS 5+ and later, you can also do this yourself using custom container controller, manually adding the child view controller views, change the frames during the gesture. Clearly, you have to do all of the custom container calls, too (e.g. `addChildViewController`, `removeChildViewController`, `willMoveToParentViewController`, `didMoveToParentViewController`, etc.). See WWDC 2011 video Implementing UIViewController Containment or Creating Custom Container View Controllers section of the View Controller Programming Guide.

Problem

Well, trick question, I know it's possible as there's a few apps doing it, notably Reeder does it very well. In Reeder, it seems that the view controller that gets popped does not get removed from memory, or whatever the typical behaviour is, because after popping and returning to the previous view controller, you can slide right-to-left to peek a little, and if you were scrolling the previous view controller before leaving, you can still see the scrolling occur. This ability to quickly jump back to the previous view controllers you were looking at, without having to preload them from scratch is exactly what I'm looking for. Basically, in iOS 7 by default when you slide to the right from the left edge of a view controller it pops it off the navigation stack. I'd love for the ability to slide to the left from the right edge to add it back. Think of this as in a web browser you're able to click the "Forward" button after pressing back. (Or in iOS 7's Safari how you can do exactly this.) Is this functionality part of iOS 7 by default and I just can't find it? Or is there any information on how to go about accomplishing it?

Original source