I am new to iOS development. I am trying to hide status bar in UIImagePickerController
. Whenever I click on \"Take photo\", status bar appears. It doesn\'t hide
You can do it with a category:
@interface UIImagePickerController (HideStatusBar)
@end
@implementation UIImagePickerController (HideStatusBar)
- (BOOL)prefersStatusBarHidden
{
return YES;
}
- (UIViewController *)childViewControllerForStatusBarHidden
{
return nil;
}
@end
Source: https://gist.github.com/psobko/9493473
I had an issue where in iOS7 my status bar was not being hidden. I hid it programmatically and it still displayed in iOS7, but when ran in iOS6 the status bar would hide appropriately. You have to go to the plist and add the following:
'view controller-based status bar appearance' and set to NO.
If you want the status bar to re-appear in other view controllers and only be hidden on a particular VC, then you set the status bar to hidden YES when the VC loads. When the VC will disappear you set the status bar hidden back to NO.
- (void)viewDidLoad
{
[super viewDidLoad];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}
and when the controller will disappear you add the following to set the status bar so it is no longer hidden and will display on the next View:
-(void)viewWillDisappear:(BOOL)animated{
[[UIApplication sharedApplication] setStatusBarHidden:NO];
}
setStatusBarHidden:withAnimation:
if you want some smooth animation
i think i solved this in a pretty simple way without subclassing and using plist. it only hides for UIImagePickerController.
this example is for bringing up the photo gallary only, but i imagine you can apply it in the same way to anywhere with in uiimagepickercontroller
- (void)showGallary
{
[CATransaction begin];
[CATransaction setCompletionBlock:^{
[[UIApplication sharedApplication] setStatusBarHidden:YES];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
}];
imgPicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[CATransaction commit];
}
Try my answer posted here if you want to keep using ViewController-Based Status Bar Appearance
.
In my case I had to use presentViewController to show UIImagePickerViewController (iOS7).
1- Set View controller-based status bar appearance to NO in .plist 2- Create a category for UIImagePickerController and in viewDidLayoutSubviews:
- (void)viewDidLayoutSubviews{
[super viewDidLayoutSubviews];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}
3- Added the two following methods to the category:
- (BOOL)prefersStatusBarHidden{
return YES;
}
- (UIViewController *)childViewControllerForStatusBarHidden{
return nil;
}
I hope this will help.
This worked fine for me:
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}
Edit: As of today i just found out that in your info.plist, if you just copy-paste view controller-based status bar appearance there it won't work ... you have to hit enter on a property, and scroll to the last one of them so you will have autocomplete to :view controller-based status bar appearance and an boolean, with no. I tried multiple times but it does not work just copying. Have a nice day.