5

I would like to disable the navigation bar while adding a child view and enable it again once I remove the child view. How to do that. A similar action when an action sheet is shown.

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
Arock
  • 397
  • 5
  • 17

6 Answers6

2

In Swift:

self.navigationController?.setNavigationBarHidden(true, animated: true)
Segev
  • 1,267
  • 16
  • 21
2

Note, that you may have to keep track of what buttons were initially disabled, if you want to avoid enabling them again this way.

I also haven't checked if this includes the back button. I'm guessing it doesn't, so you'll have to account for this if needed too.

NSArray* allBarButtons = [self.navigationController.navigationBar.topItem.leftBarButtonItems arrayByAddingObjectsFromArray:self.navigationController.navigationBar.topItem.rightBarButtonItems];
for (UIBarButtonItem* barButton in allBarButtons) {
     barButton.enabled = NO;
}
narco
  • 830
  • 8
  • 21
1

Use (Objective-C):

[self.navigationController setNavigationBarHidden:YES animated:YES];
JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
Abin George
  • 644
  • 6
  • 21
  • I need to disable and give it a faded look just like the ActionSheet does. – Arock Feb 27 '14 at 10:49
  • 2
    set the alpha value of the navigation bar to some 0.6 or 0.5 for fading and when wanted normal, reset it to 1. navigationBar.alpha=0.5f; – Abin George Feb 27 '14 at 10:57
  • 1
    That works but the status bar is now fading out in iOS7 – Arock Feb 27 '14 at 11:13
  • 1
    That is unexpected. because the statusbar will be having an alpha 1. you may try changing the statusbar type lightcontent. if still the problem persists, am sorry bro. – Abin George Feb 27 '14 at 11:16
1

In Swift 4, place the code below inside viewDidLoad() of your ViewController.

self.navigationController?.isNavigationBarHidden = true
Cons Bulaquena
  • 2,083
  • 2
  • 26
  • 24
0
self.navigationController.navigationBar.topItem.leftBarButtonItem.enabled = NO;
self.navigationController.navigationBar.topItem.rightBarButtonItem.enabled = NO;
self.navigationController.navigationBar.topItem.backBarButtonItem.enabled = NO;
Marek R
  • 32,568
  • 6
  • 55
  • 140
0

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

reza_khalafi
  • 6,230
  • 7
  • 56
  • 82