如何在调用 UIImagePickerController 后隐藏状态栏?

How to hide status bar after calling UIImagePickerController?

我想在 iOS 10.2 上调用 UIImagePickerController 后隐藏状态栏。

有几个问题的答案不适用于 Swift 3.0。

建议的答案是:

所以我尝试了:

extension UINavigationController{
    open override var prefersStatusBarHidden: Bool{
        return true
    }
}

所以我尝试了:

extension UIImagePickerController{
    open override var prefersStatusBarHidden: Bool{
        return true
    }
}

所以我尝试了:

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

None 以上解决方案对我有用。

您正在添加 UINavigationControllerDelegate 的委托方法,如下所示。

class PersonalInfoVC: UIViewController, UIImagePickerControllerDelegate , UINavigationControllerDelegate{

添加代理并在其中隐藏状态栏。

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

状态栏可以通过以下扩展名永久隐藏 UIImagePickerController :

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

    open override var prefersStatusBarHidden: Bool {
        return true
    }
}

这适用于 Swift 3,iOS 10。

显示视图控制器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
    }
})

None 这些答案对我有用 iOS 13。在呈现图像选择器之前,我必须在呈现视图控制器上设置此标志:

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