I have a UINavigationController
with a visible Navigation Bar.
I have one particular UIViewController
which I'd like to hide the status bar when pushed into the navigation stack. Once this viewController is popped I'd like to show the status bar again.
I'm hiding the bar in the viewWillAppear
method of my UIViewController
like this:
- (void) viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.navigationController setWantsFullScreenLayout:YES];
[[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES];
}
Note that I'm setting setWantsFullScreenLayout:YES
here for clarity, but I'm actually just setting this property in Interface Builder.
The problem: The navigation bar of the NavigationController doesn't move up to take the space of the now hidden status bar.
A hacky solution The only thing I found that worked to refresh the position of the nav bar was to hide it and show it again, like this:
[[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES];
[self.navigationController setNavigationBarHidden:YES animated:NO];
[self.navigationController setNavigationBarHidden:NO animated:NO];
but this is clearly a hack, there has got to be a better way.
Other things I tried:
I tried calling the
[super viewWillAppear]
after hiding the status bar, i.e. at the end of my method.I tried setNeedsLayout on the navigationController.view like this:
[[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES]; [self.navigationController.view setNeedsLayout];
but that doesn't seem to work.
Any help appreciated. Thanks