IOS 7 added a slide to the right to pull the view controller from the stack. Can I add it back by sliding to the left?

Well, the trick, I know that this is possible, since there are several applications there, especially Reeder . It is very good.

In Reeder, it seems that the view controller that appears is not deleted from the memory or something that is typical of normal behavior, because after the appearance and return to the previous view controller, you can move left and right to look a little, and if you have scrolled the previous view controller before leaving, you can still see the scrolling. This ability to quickly return to the previous view controllers that you looked at without first downloading them from scratch is exactly what I'm looking for.

Basically, in iOS 7, by default, when you move to the right from the left edge of the view controller, it pops it from the navigation stack. I wish you could slide left from the right edge to add it back. Think about it, as in a web browser you can click the "Forward" button after clicking. (Or in iOS 7 Safari, how can you do just that.)

Is this functional part of iOS 7 by default and I just can't find it? Or is there information on how to do this?

+6
source share
4 answers

The options depend on the versions of iOS that you are trying to support.

  • In iOS 7+, you can use custom controller transitions and make interactive controller transitions. For a conceptual description, see WWDC 2013 Video Custom Transitions Using View Controllers. The main process:

    • Create an animation controller that defines what the animation should be. An animation controller is an object that corresponds to UIViewControllerAnimatedTransitioning . (Note that it may seem odd to define a custom animation controller for something standard like push animation, but below you will see that we want the gesture recognizer to interact with the interaction controller, but you cannot define a custom interaction controller if you also do not define a custom animation controller.)

    • Create an instance of the interaction controller. You can create your own interaction controller class that corresponds to UIViewControllerInteractiveTransitioning , but the easiest way is to instantiate a UIPercentDrivenInteractiveTransition object.

    • Now that you have an interaction controller, you can associate a gesture recognizer (for example, a UIScreenEdgePanGestureRecognizer ). The gesture recognizer will call the updateInteractiveTransition interaction controller to indicate the progress of the animation, as it corresponds to a continuous gesture.

    • It is clear that if you are going to recognize napkins from the right edge as a “push” to a certain scene, then you will follow what will be in this “next” scene. Sometimes you will have a predefined series of controllers. Sometimes you just keep a stack of view controllers that you previously popped up so you can scroll from the right side to push them back. It just depends on the desired UX.

    IOS 7 client transitions provide incredible control when setting up animations and gestures associated with an interactive transition. But this requires a little work.

  • If you're just looking for an easier way to just make slide transitions between multiple view controllers, you can use the UIPageViewController . In iOS 6 and later, you can use transitionStyle UIPageViewControllerTransitionStyleScroll . (Unfortunately, in iOS 5, you only had to go to the page.)

  • In iOS 5+ and later, you can also do it yourself using the container’s user controller, manually adding child view controller views, and changing frames during gestures. Obviously, you must also make all custom container calls (e.g. addChildViewController , removeChildViewController , willMoveToParentViewController , didMoveToParentViewController , etc.). See WWDC 2011 Video Implementing the UIViewController Containment or Creating Custom Container View Controllers in the View Controller Programming Guide.

+8
source

What I would do is create a custom subclass of UINavigationController and give it the (strong) lastPoppedVC property. Then override the implementation of popViewControllerAnimated to save the view controller that is exposed to lastPoppedVC.

Also set up a gesture recognizer for slide-from-left gestures, which pushes lastPoppedVC back onto the stack. This will require some intervention, as I don't think you could attach a gesture recognizer to the contents of the navigation controller. You probably need to connect a gesture recognizer to each VC that you click on your own navigation controller stack, and devise a way to trigger push back. (You might want to create a UIViewController category that has a handleSwipeFromLeftGesture method that sends a message to the managing navigation controller.)

+2
source

Animation itself is not a problem. Here's the code where, if you drag on the right side another view of the controller controller, appears on the right. This is a tab bar controller, not a navigation controller, but all of these principles are exactly the same:

https://github.com/mattneub/Programming-iOS-Book-Examples/blob/master/bk2ch06p296customAnimation2/ch19p620customAnimation1/AppDelegate.m

Thus, the drag gesture on the right to bring up another kind of controller controller is completely simple.

The only problem is to interpret what the logical drag on the right implies. In the code I just pointed out, it’s clear what dragging means left or right: it means “switch to the left / right view controller if there is one” (in the tab bar controller) - and I presented the logic to do this is exactly so. Well, in the case of the navigation controller, it’s clear what the drag on the left is: “return”. But I can’t imagine which view controller you expect, I need to push it onto the stack when the user pulls to the right; you will need to specify the logic to somehow indicate it.

+2
source

I have a creative solution for this.

Create an NSIndexPath object (for example: NSIndexPath *previousIndexPath) for your view controller, which will save indexPath for the last viewControllerPushed.

Update it every time you press a new view controller (in the -didSelectRowAtIndexPath or -prepareForSegue ) so when you use UIScreenEdgePanGestureRecognizer , you can directly call [self didSelectRowAtIndexPath:previousIndexPath] .

0
source

Source: https://habr.com/ru/post/959106/


All Articles