How to hide Navigation Bar without losing slide-back ability How to hide Navigation Bar without losing slide-back ability ios ios

How to hide Navigation Bar without losing slide-back ability


Tested with Swift 2 the solution of @gabbler, if you use

self.navigationController?.navigationBar.hidden = true

Swift 3.0

self.navigationController?.navigationBar.isHidden = true

instead of

self.navigationController?.navigationBarHidden = true

the swipe back gesture works like a charm!


Found the 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 .h file, conform to UIGestureRecognizerDelegate


Use

self.navigationController.navigationBar.hidden = YES;

or add this line in viewWillAppear:

self.navigationController.interactivePopGestureRecognizer.delegate = self;

It seems the interaction is not effective, adding this line and make the view controller conforms to the UIGestureRecognizerDelegate protocol will make it work.