IOS – UINavigation full screen slide  real return (a)

Main points

InteractivePopGestureRecognizer is the UINavigationController comes with gestures, when we customize the return button of the navigation bar, this gesture will automatically lapse, that is, can not slide back.

condition

In many cases we have to customize the return button for the navigation bar, but we also want to slide back to the top level.

thinking

Since it’s automatically out of order, we’ll tell you when it will take effect.

  • In the non root controller (for sliding back to the upper level)
  • The failure in the root controller (the root controller is removed, of course, the system will not let us remove it, but there will be a bug
    IOS - UINavigation full screen slide  real return (a)
    ) Apple’s official document translation: the first being added to the controller as a never root controller stack

step

A custom UINavigationController, which is inherited from UINavigationController, called LXFNavigationController, will set their own agency, comply with the UINavigationControllerDelegate protocol, realization method of navigationController:didShowViewController:animated: agent

Code

LXFNavigationController.m

Agent / @property / * * gesture system (nonatomic, strong) ID popGesture;
- (void) viewDidLoad {[super viewDidLoad]; / / self.popGesture = self.interactivePopGestureRecognizer proxy gesture recording system; self.delegate = self;}
#pragma mark - UINavigationControllerDelegate / / when the controller display call at the end of - (void) navigationController: (UINavigationController * navigationController) didShowViewController: (UIViewController *) viewController animated: (BOOL animated) {/ / according to the advanced after if stack (self.viewControllers[0] = = viewController) {/ / self.interactivePopGestureRecognizer.delegate / / root controller reduction agent = self.popGesture;} else {/ / / controller empty gesture agent can achieve sliding returns, iOS6 does not support self.interactivePopGestureRecognizer.delegate = nil;} / / if the current controller is the root controller, make the gesture or gesture will root failure, remove if (self.viewControllers.count controller = = 1) {self.interactivePopGestureRecognizer.enabled} {self.interactivePopGestureRecognizer.enabled = NO; else = YES;}}
IOS - UINavigation full screen slide  real return (a)
only on the left side of the slide is valid

Last two sentences

This can be, but pay attention to, and now is the realization of the sliding return function, and there is no full screen slide back ~ ~ next look at the next bar
iOS – to achieve full screen slide UINavigation return (two)