how to hide top bar in UIViewcontroller when i push from navigation controller using pushViewController ? any help please?
Asked
Active
Viewed 3.7k times
3 Answers
117
Put this code in the view controller you want to hide the navigation bar for.
- (void) viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES animated:animated];
}
And you may also want to stick this in there, depending on your needs:
- (void) viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self.navigationController setNavigationBarHidden:NO animated:animated];
}

Ed Marty
- 39,590
- 19
- 103
- 156
-
I would like to add to the question, how to make it hide/show when the user taps towards where it is. Ie: like in the photos app. – fearmint Oct 24 '09 at 17:44
-
3You just put that setNavigationBarHidden call wherever you like, when you need to hide the nav bar. – Kendall Helmstetter Gelner Oct 24 '09 at 22:10
-
@Ed Marty Can we hide the navigation bar in storyboard? – three-blocks Apr 26 '17 at 08:37
13
Here's how to do it in Swift 3:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.navigationController?.setNavigationBarHidden(true, animated: animated)
}
P.S. I found that if you set animated to false
, a black bar appears on push. But when it is set to true
it's smooth as silk!

dustinrwh
- 888
- 1
- 14
- 16
1
For iOS 8 May be this work around could work it
CATransition* transition = [CATransition animation];
transition.duration = 0.3;
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromRight;
[self.navigationController.view.layer addAnimation:transition forKey:kCATransition];
[self.navigationController setNavigationBarHidden:TRUE animated:FALSE];
[self.navigationController pushViewController:productViewObj animated:FALSE];
[productViewObj.navigationController setNavigationBarHidden:TRUE animated:FALSE];
[productViewObj release];

Zahur
- 181
- 3
- 10