我的应用程序的状态栏样式是白色的,除非出现图像选择器 Controller 并且我已经扩展了我的 UINavigationController
但它似乎不适用于仅在推送 View 上出现的任何 View 有人有解决办法吗??
extension UINavigationController {
open override var preferredStatusBarStyle: UIStatusBarStyle {
return topViewController?.preferredStatusBarStyle ?? .lightContent
}
}
我也尝试过这个方法,但是 navigationController 是一个 let 和
preferredStatusBarStyle
是只读的
func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) {
viewController.navigationItem.title = "willShow"
navigationController.preferredStatusBarStyle = UIStatusBarStyle.lightContent
}
最佳答案
当您以模态方式呈现某些内容并希望它确定您需要设置的状态栏样式时 modalPresentationCapturesStatusBarAppearance = true
例如:
let navigationController = UINavigationController(rootViewController: MyViewController())
navigationController.modalPresentationCapturesStatusBarAppearance = true
present(navigationController, animated: true)
您还需要检查当前 UINavigationController
是否为 UIImagePickerController
并从 preferredStatusBarStyle
返回 .lightContent
> 因为 UIImagePickerController
更喜欢开箱即用的 .default
。
open override var preferredStatusBarStyle: UIStatusBarStyle {
if self is UIImagePickerController {
return .lightContent
}
return topViewController?.preferredStatusBarStyle ?? .lightContent
}
关于ios - 快速更改图像选择器首选状态栏样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55548215/