为什么我的状态栏没有改变首选样式?

Nic*_*hrn 2 statusbar ios swift swift3

我已在我的文件中View controller-based status bar appearance设置为。YESInfo.plist

视图控制器(不在导航堆栈中)通过模态转场呈现。在其中,我对 Swift 3/iOS 10 进行了以下属性覆盖:

override var preferredStatusBarStyle: UIStatusBarStyle { return .lightContent }
Run Code Online (Sandbox Code Playgroud)

尽管如此,状态栏仍保留其默认(深色)样式。然而,当我打印preferredStatusBarStyleviewDidLoad,我得到rawValue1。检查出的文件1指的是.lightContent

我试图在状态栏的改变风格.lightContent,因为该视图包含UIVisualEffectViewUIBlurEffectStyle价值dark

我做错了什么吗?

Nic*_*hrn 6

在马特的回答的帮助下,我能够解决我的问题。我必须在以下内容中使用viewDidLoad

modalPresentationCapturesStatusBarAppearance = true
Run Code Online (Sandbox Code Playgroud)

当我尝试 matt 的解决方案时,我收到了两个编译错误:Cannot override mutable property with read-only property 'modalPresentationCapturesStatusBarAppearance'Getter for 'modalPresentationCapturesStatusBarAppearance' with Objective-C selector 'modalPresentationCapturesStatusBarAppearance' conflicts with getter for 'modalPresentationCapturesStatusBarAppearance' from superclass 'UIViewController' with the same Objective-C selector


mat*_*att 5

将其添加到模态呈现的视图控制器中:

override var modalPresentationCapturesStatusBarAppearance: Bool { 
    return true
}
Run Code Online (Sandbox Code Playgroud)