How to Hide Status Bar in Uiimagepickercontroller

How to hide status bar in UIImagepickercontroller?

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

How to hide status bar after calling UIImagePickerController?

The status bar can be permanently hidden with the following extension to UIImagePickerController :

extension UIImagePickerController {
open override var childViewControllerForStatusBarHidden: UIViewController? {
return nil
}

open override var prefersStatusBarHidden: Bool {
return true
}
}

This is working for Swift 3, on iOS 10.

UIImagePickerController breaks status bar appearance

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...

How to make UIImagePickerController StatusBar lightContent style?

Just three steps:

1: Add UINavigationControllerDelegate,UIImagePickerControllerDelegate to your

@interface yourController ()<>

2: imagePickerController.delegate = self;

3:

-(void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
}

Changing Image Picker Preferred Status Bar Style swift

When you present something modally and you want it to determine the status bar style you need to set modalPresentationCapturesStatusBarAppearance = true

For example:

let navigationController = UINavigationController(rootViewController: MyViewController())
navigationController.modalPresentationCapturesStatusBarAppearance = true
present(navigationController, animated: true)

You'll also need to check if the current UINavigationController is a UIImagePickerController and return .lightContent from preferredStatusBarStyle as UIImagePickerController has a prefers the .default out of the box.

open override var preferredStatusBarStyle: UIStatusBarStyle {
if self is UIImagePickerController {
return .lightContent
}
return topViewController?.preferredStatusBarStyle ?? .lightContent
}


Related Topics



Leave a reply



Submit