我的应用程序的状态栏样式为白色,除非显示了图像选择器控制器并且我已经扩展了UINavigationController
,但是它似乎无法在仅存在于推送视图中的任何视图上起作用解决方案?
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
}
答案 0 :(得分:1)
当您以模态方式呈现某些内容并希望其确定状态栏样式时,您需要设置modalPresentationCapturesStatusBarAppearance = true
例如:
let navigationController = UINavigationController(rootViewController: MyViewController())
navigationController.modalPresentationCapturesStatusBarAppearance = true
present(navigationController, animated: true)
您还需要检查当前的UINavigationController
是否为UIImagePickerController
,并从.lightContent
返回preferredStatusBarStyle
,因为UIImagePickerController
偏爱{{ 1}}开箱即用。
.default