How to hide status bar after calling UIImagePickerController?

2.2k Views Asked by At

I want to hide the status bar after calling UIImagePickerController on iOS 10.2.

There are several questions with answers that don't work for Swift 3.0.

The suggested answers are:

  • extend UINavigationController to override preferStatusBarHidden, because UIImagePickerController is a subclass of UINavigationController.

So I tried:

extension UINavigationController{
    open override var prefersStatusBarHidden: Bool{
        return true
    }
}
  • extend UIImagePickerController to override prefersStatusBarHidden.

So I tried:

extension UIImagePickerController{
    open override var prefersStatusBarHidden: Bool{
        return true
    }
}
  • create and use a subclass of UIImagePicker

So I tried:

class MyImagePickerController: UIImagePickerController{
    override var prefersStatusBarHidden: Bool{
        return true
    }
}

None of the above solutions work for me.

4

There are 4 best solutions below

0
On BEST ANSWER

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.

1
On

You are adding the delegate method method of UINavigationControllerDelegate like below.

class PersonalInfoVC: UIViewController, UIImagePickerControllerDelegate , UINavigationControllerDelegate{

Adding the delegate and hide the status bar in it.

func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool){
    UIApplication.shared.isStatusBarHidden = true
}
0
On

None of those answers worked for me on iOS 13. I had to set this flag on the presenting view controller before presenting the image picker:

viewController.modalPresentationCapturesStatusBarAppearance = YES; [viewController presentViewController:picker animated:YES completion:nil];

0
On

The status bar can be hidden and show when presenting view controller UIImagePickerController swift 4+

picker.dismiss(animated: true, completion: {
    if let statusBar = UIApplication.shared.value(forKey: "statusBar") as? UIView {
        statusBar.isHidden =  true
    }
})

picker.dismiss(animated: true, completion: {
    if let statusBar = UIApplication.shared.value(forKey: "statusBar") as? UIView {
        statusBar.isHidden =  false
    }
})