1

I'm using nibs, not storyboard. Anyways, I am doing a push from one view controller to the next:

[self.navigationController pushViewController:vc animated:YES];

but on the next view controller "vc", I want the navigation bar to be hidden. However, I still want to be able to swipe left to go the previous screen, as well as be able to place a back button that will bring the user back.

However, when I do this [self.navigationController setNavigationBarHidden:YES animated:animated]; in the next view controller, this hides the navigation bar, but you can no longer swipe to navigate back.

How can I have this swipe back functionality, and also place the back button on the screen (just without the navigation bar?)

I'm trying to mimic the behavior of Yahoo News Digest - note that it has navigation buttons, and swipe to go back, but no navigation bar. Additionally, the back button disappears when you scroll down.

I've tried making the navigation bar translucent, but then the bar blocks touches, so that the user can't tap content under the bar. Any ideas? Thanks!

enter image description here

Ken
  • 530
  • 4
  • 11
  • 30
  • working solution by HorseT: http://stackoverflow.com/questions/24710258/no-swipe-back-when-hiding-navigation-bar-in-uinavigationcontroller – matteok Jul 20 '16 at 11:28

3 Answers3

3

Swift

You can hide the navigationBar with this method:

self.navigationController?.navigationBar.isHidden = true
// or
self.navigationController?.setNavigationBarHidden(true, animated: true)

Enable interactivePopGestureRecognizer documentation

self.navigationController?.interactivePopGestureRecognizer?.delegate = self as! UIGestureRecognizerDelegate

// Enable gesture to pop the top view controller off the navigation stack
self.navigationController?.interactivePopGestureRecognizer?.isEnabled = true

// Make an extension for your View Controller
extension MyViewController: UIGestureRecognizerDelegate {}

OR

Add EdgePanGestureRecognizer to recognize left swipe and then go back:

// in viewDidLoad
let edgePan = UIScreenEdgePanGestureRecognizer(target: self, action: #selector(leftEdgeSwipe))
edgePan.edges = .left

view.addGestureRecognizer(edgePan)

// Method to go back
@objc func leftEdgeSwipe(_ recognizer: UIScreenEdgePanGestureRecognizer) {
   if recognizer.state == .recognized {
      self.navigationController?.popViewController(animated: true)
   }
}
Bohdan Boch
  • 59
  • 1
  • 5
0

you can do that its very simple just hide ur navigation bar

[self.navigationController setNavigationBarHidden:YES animated:animated];

and add Swipe Gesture to navigate back to the pervious view

- (void)viewDidLoad
{
   [super viewDidLoad];

 //Add Swipe Gesture to navigate back to view
UISwipeGestureRecognizer *backtoview = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeHandler)];
[self.view addGestureRecognizer: backtoview];
}


-(void)swipeHandler{
   [self.navigationController popViewControllerAnimated:YES];
}

If you want direction you can add directions to swipe gesture and if you want with button event then add the custom button and add the same method to the button action

this will help you!

alex
  • 518
  • 3
  • 10
  • 1
    but it's not an interactive swipe :( and there is no `UIViewControllerTransitionCoordinator` involved ;'-( – Michael Mar 22 '15 at 11:36
  • exactly, a UISwipeGestureRecognizer is not ideal because I'm looking to preserve the native interactive swipe behavior – Ken Mar 22 '15 at 22:24
0
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];    
    self.navigationController.navigationBar.alpha = 0;
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    self.navigationController.navigationBar.alpha = 1;
}
Masatsugu Hosoi
  • 420
  • 6
  • 7