Hide and display functions of navigation bar and tabBar when iOS interface jumps

  • 2021-10-16 05:10:22
  • OfStack

1. When the A page wants push to B and needs to hide the navigation bar of the B page, we only need to override the following two methods in the A page:


override func viewWillAppear(animated: Bool) {
  super.viewWillAppear(animated)
  self.navigationController?.setNavigationBarHidden(true, animated: true)
  }
 override func viewWillDisappear(animated: Bool) {
   super.viewWillDisappear(animated)
   self.navigationController?.setNavigationBarHidden(false, animated: true)
  }

Note: self.navigationController?.navigationBarHidden = false This may cause the navigation bar to flash when switching between the controller with the navigation bar hidden and the controller without the navigation bar hidden. You can solve this problem by setting its hidden method with the above call.

2. When we need to hide tabBar when jumping from A page push to B page, write the following code on A page:


 self.hidesBottomBarWhenPushed=YES;
  BViewController *bvc=[[BViewController alloc]init];
  [self.navigationController pushViewController:bvc animated:YES];
  self.hidesBottomBarWhenPushed=NO;
  // Finally 1 Sentences can be guaranteed in back Back to A When, tabBar Will return to normal display 

Related articles: