The navigation bar is still there when you jump to it

let testVC = TestViewController() testVC.hidesBottomBarWhenPushed = true self.navigationController? .pushViewController(testVC, animated: true)Copy the code

But then you have to write every jump once, which is a lot of trouble

Intercept this method to hide the tabbar from the target controller when the navigation bar is pushed

XMGNavigationController is the navigation bar in your project so this is the class that you’re going to use to set up root

  • Swift simplified version
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        viewController.hidesBottomBarWhenPushed = true
        super.pushViewController(viewController, animated: animated)
    }
Copy the code
  • OC (This is the way to write the navigation bar of OC in my project)
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {// hide TabBar if (self.childViewControllers.count > 0) { viewController.hidesBottomBarWhenPushed = YES; / / solution to push after multiple controllers, popToRootViewController Tabbar disappear question ios14 problems if (self. ChildViewControllers. Count > 1) { viewController.hidesBottomBarWhenPushed = NO; } } [super pushViewController:viewController animated:animated]; }Copy the code
  • If we want to jump to a controller that needs a custom navigation bar we need to hide the navigation bar
override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) navigationController? .setNavigationBarHidden(true, animated: } // Override func viewWillDisappear(_ animated: Bool) { super.viewWillDisappear(animated) navigationController? .setNavigationBarHidden(false, animated: true) }Copy the code

So you can’t go back and you can only add buttons but I want to use gestures and notice this navigation bar right here you have to use this class so that you can change your code in the navigation bar controller class that you wrotePop it back with a gesture

override func viewDidLoad() { super.viewDidLoad() // 1. Use the runtime, print gestures all attributes in the guard let the targets = interactivePopGestureRecognizer! .value(forKey: "_targets") as? [NSObject] else { return } let targetObjc = targets[0] let target = targetObjc.value(forKey: "target") let action = Selector(("handleNavigationTransition:")) let panGes = UIPanGestureRecognizer(target: target, action: action) view.addGestureRecognizer(panGes) }Copy the code
  • InteractivePopGestureRecognizer this is gesture of the navigation bar, it is not very big is on the left side of the range of a little bit

  • Get the targt and action for this gesture and add those to the new gesture so that the new gesture has this function
  • And then add the gesture to the View