How to hide the navigation bar without losing slides

I have a UITableView, and it has a navigation bar (obtained from the UINavigationViewController), it is able to go back using a finger.

I tried to hide the navigation bar, but retained the ability to slide back, code:

- (void)viewWillAppear:(BOOL)animated { [[self navigationController] setNavigationBarHidden:YES animated:YES]; } 

This successfully hid the navigation bar, however I can no longer return to the last screen.

Is there a way to hide the navigation bar but retain the ability to roll back?

+15
ios objective-c xcode
Oct 13 '14 at 2:44
source share
6 answers

Found a solution:

 - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; // hide nav bar [[self navigationController] setNavigationBarHidden:YES animated:YES]; // enable slide-back if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) { self.navigationController.interactivePopGestureRecognizer.enabled = YES; self.navigationController.interactivePopGestureRecognizer.delegate = self; } } - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer { return YES; } 

And in the .h file, compatible with UIGestureRecognizerDelegate

+17
Oct 13 '14 at 2:56
source share

Tested with Swift 2 @gabbler solution if you use

 self.navigationController?.navigationBar.hidden = true 

Swift 3.0

 self.navigationController?.navigationBar.isHidden = true 

instead

 self.navigationController?.navigationBarHidden = true 

with a swipe back gesture works like a charm!

+31
May 07 '16 at 18:09
source share

Use

 self.navigationController.navigationBar.hidden = YES; 

or add this line to viewWillAppear:

 self.navigationController.interactivePopGestureRecognizer.delegate = self; 

The interaction seems to be inefficient by adding this line and making the view controller compatible with the UIGestureRecognizerDelegate protocol to make it work.

+6
Oct 13 '14 at 2:49
source share

Be sure to include:

 self.navigationController.navigationBar.hidden = YES; 

and

 self.navigationController.interactivePopGestureRecognizer.delegate = self; 

and

 if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) { self.navigationController.interactivePopGestureRecognizer.enabled = YES; } 

It should look like this:

 - (void)viewWillAppear:(BOOL)animated { self.navigationController.navigationBar.hidden = YES; self.navigationController.interactivePopGestureRecognizer.delegate = self; if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) { self.navigationController.interactivePopGestureRecognizer.enabled = YES; } } - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer { return YES; } 
+3
Oct 13 '14 at 2:52
source share

for Xamarin Forms I was struggling with this, so at first it’s not NavigationRenderer you will get NavigationController null instead of using PageRenderer:

 [assembly: Xamarin.Forms.ExportRenderer(typeof(ContentPage), typeof(ContentPageRenderer))] namespace sample { class ContentPageRenderer : PageRenderer { public override void ViewWillAppear(bool animated) { base.ViewDidAppear(animated); var navctrl = this.ViewController.NavigationController; navctrl.InteractivePopGestureRecognizer.Delegate = new UIGestureRecognizerDelegate(); navctrl.InteractivePopGestureRecognizer.Enabled = true; } } } 
+1
Aug 09 '17 at 8:38 on
source share

If hiding the navigation bar did not help, try changing the rectangle of the navigation bar and see?

navBarBgFrame.origin.y = - navBarBgFrame.size.height;

0
Oct 13 '14 at 5:30
source share



All Articles