I have a UINavigationController
with a visible Navigation Bar.
I have one particular UIViewController
which I\'d like to hide the status bar when p
I found the solutions above didn't quite work when the view is in the middle of an animated presentation, so I deferred hiding the status bar as follows:
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
// doesn't work immediately because modal view has to finish loading
dispatch_async(dispatch_get_main_queue(), ^(){
[[UIApplication sharedApplication] setStatusBarHidden:YES];
self.view.frame = [UIScreen mainScreen].applicationFrame;
});
}
You should try resizing the frame of your UIViewControllers's
view after you have hidden the StatusBar. The applicationFrame updates it's origin.y and size.height during the setStatusBarHidden:animated:
method.
CGRect rect = [UIScreen mainScreen].applicationFrame;
self.view.frame = rect;
[self.view setNeedsLayout];
In your root view controller (where you want to show the status bar):
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[UIApplication sharedApplication] setStatusBarHidden:NO animated:YES];;
}
In the view controller you push on the stack (where you want to hide the status bar):
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES];;
}
Edit:
I realize now you want to hide the status bar. Got them mixed up since you were showing/hiding the nav bar in the code you posted. My mistake. It's essentially the same code, anyway:
In your root view controller (where you want to show the status bar):
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[UIApplication sharedApplication] setStatusBarHidden:NO animated:YES];
}
In the view controller you push on the stack (where you want to hide the status bar):
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES];
}
I just tested this with an existing project and it worked.
There are two ways that you can do what you are asking.
One is to manually move the navigation bar:
In viewWillAppear:
[UIApplication sharedApplication].statusBarHidden = YES;
self.view.frame = [UIScreen mainScreen].applicationFrame;
CGRect frame = self.navigationController.navigationBar.frame;
frame.origin.y = 0;
self.navigationController.navigationBar.frame = frame;
In viewWillDisappear:
[UIApplication sharedApplication].statusBarHidden = NO;
CGRect frame = self.navigationController.navigationBar.frame;
frame.origin.y = 20.0;
self.navigationController.navigationBar.frame = frame;
Things will also be okay if you are willing to turn off the navigation bar as well, although I suspect that is not what you wanted:
[UIApplication sharedApplication].statusBarHidden = YES;
self.navigationController.navigationBarHidden = YES;