The main points of

InteractivePopGestureRecognizer is UINavigationController with gestures, when we have a custom navigation bar back button, this gesture is null and void automatically, that is unable to slide back.

conditions

In many cases we had to customize the back button of the navigation bar, but we also had to slide back to the previous level.

Train of thought

If it’s automatic, let’s just tell it when it goes into effect.

  • Works under a non-root controller (used to slide back up a level)
  • Failure under the root controller (prevent root controller from being removed, of course the system won’t let us remove it, just bug)





    Apple official documentation notes

    The first controller added becomes the root controller that is never pushed out of the stack

steps

Create a custom UINavigationController that inherits from UINavigationController named LXFNavigationController, set the agent to itself, Abide by the agreement UINavigationControllerDelegate, navigationController proxy methods: didShowViewController: animated:

code

LXFNavigationController.m

/** System gesture proxy */
@property(nonatomic.strong) id popGesture;Copy the code
- (void)viewDidLoad {
 [super viewDidLoad];

  // Record system gesture proxy
  self.popGesture = self.interactivePopGestureRecognizer;
  self.delegate = self;
}Copy the code
#pragma mark - UINavigationControllerDelegate
// called when the controller is displayed
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    // According to the stack first out
    if (self.viewControllers[0] == viewController) { // Root controller
        // Restore the proxy
        self.interactivePopGestureRecognizer.delegate = self.popGesture;
    } else { // Non-controller
        // Clear the gesture proxy and swipe back, iOS6 doesn't support it
        self.interactivePopGestureRecognizer.delegate = nil;
    }
    // If the current controller is the root controller, deactivate the gesture, otherwise the gesture will remove the root controller
    if (self.viewControllers.count == 1) {
        self.interactivePopGestureRecognizer.enabled = NO;
    } else {
        self.interactivePopGestureRecognizer.enabled = YES; }}Copy the code




Only left edge sliding works

One last word

IOS – UINavigation Full screen swipe return iOS – UINavigation full screen swipe return