4

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.

Community
  • 1
  • 1
David Roman
  • 421
  • 4
  • 11

4 Answers4

12

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.

Sam Fischer
  • 1,442
  • 19
  • 35
2

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
}
Kirit Modi
  • 23,155
  • 15
  • 89
  • 112
1

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];

Nik Bhatt
  • 373
  • 3
  • 12
0

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
    }
})
Sami Ahmed Siddiqui
  • 2,328
  • 1
  • 16
  • 29