Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide status bar after calling UIImagePickerController?

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.

like image 555
David Roman Avatar asked Dec 08 '22 19:12

David Roman


1 Answers

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.

like image 180
Sam Fischer Avatar answered Feb 24 '23 01:02

Sam Fischer