UIImagePickerController breaks status bar appearance
Solution 1:
None of the solutions above worked for me, but by combining Rich86man's and iOS_DEV_09's answers I've got a consistently working solution:
UIImagePickerController* imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
and
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}
Regarding this awesome solution. For 2014 / iOS8 I found in some cases you need to ALSO include prefersStatusBarHidden
and, possibly, childViewControllerForStatusBarHidden
So...
-(void)navigationController:(UINavigationController *)navigationController
willShowViewController:(UIViewController *)viewController
animated:(BOOL)animated
{
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}
-(BOOL)prefersStatusBarHidden // iOS8 definitely needs this one. checked.
{
return YES;
}
-(UIViewController *)childViewControllerForStatusBarHidden
{
return nil;
}
-(void)showCamera
{
self.cameraController = [[UIImagePickerController alloc] init];
self.cameraController.delegate = (id)self; // dpjanes solution!
etc...
Solution 2:
I faced this same issue today. Here is my solution.
In the view controller who calls the image picker, set yourself as the delegate of the image Picker. (You're probably already doing this)
UIImagePickerController* imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
Since UIImagePickerController is a type of Navigation controller, you're also setting yourself as the UINavigationController delegate. Then :
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
}
Replace UIStatusBarStyleLightContent with whatever style you are looking for.
Solution 3:
The accepted answer will work if you have the 'View controller-based status bar appearance' set to NO in your .plist file. If indeed you need to control the status bar in some other view controllers and have this option set to YES, the other way to make UIImagePickerController to behave correctly is by subclassing it
// .h
@interface MYImagePickerController : UIImagePickerController
@end
// .m
@implementation MYImagePickerController
- (UIStatusBarStyle)preferredStatusBarStyle
{
return UIStatusBarStyleLightContent; // change this to match your style
}
@end
Solution 4:
i faced the same problem.
here is my solution. put this in the viewWillAppear of the view controller from which you are opening the image pickerview
-(void) viewWillAppear:(BOOL)animated{
[super viewWillAppear:YES];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}
Solution 5:
Can you try this. I think needsStatusBarApperanceUpdate will work.
1 -Set UIViewControllerBasedStatusBarAppearance to NO.
2- Call [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
3- [self setNeedsStatusBarAppearanceUpdate];