Why does the status bar appear when popoverPresentationController is called in Swift?

无人久伴 提交于 2019-12-04 19:55:50

The ImagePickerController is very keen on displaying a status bar, regardless of your app settings. I have managed to surpress it by subclassing ImagePickerController and overriding viewWillAppear and prefersStatusBarHidden:

override func viewWillAppear(animated: Bool) {
    super.viewWillAppear(animated)
    self.setNeedsStatusBarAppearanceUpdate()
}

override func prefersStatusBarHidden() -> Bool {
    return true
}

This solution is fine if your imagePicker sourceType is .SavedPhotosAlbum but doesn't work so well if sourceType is .PhotoLibrary. The latter source type presents you with navigation options within the imagePickerController. While the first screen's status bar is under your control, you lose that control as soon as you navigate to Moments or Camera Roll. The status bar reappears and - worse - animation transitions between the viewControllers are really messed up. You can get more control over the process by intercepting UINavigationController delegate methods (UIImagePickerController is a subclass of UINavigationController), but I have only succeeded well with soureType = .SavedPhotosAlbum

EDIT

you may also have to include this:

override func childViewControllerForStatusBarHidden() -> UIViewController? {
    return nil;
}

for completely mysterious reasons!

EDIT2

Putting it all together...

class MyImagePickerController: UIImagePickerController {

    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
        self.setNeedsStatusBarAppearanceUpdate()
    }

    override func prefersStatusBarHidden() -> Bool {
        return true
    }

    override func childViewControllerForStatusBarHidden() -> UIViewController? {
        return nil;
    }

}

Then you change this line:

let picker = UIImagePickerController()

to:

let picker = MyImagePickerController()
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!