如何在iOS 9中隐藏单个视图控制器的状态栏?

问题描述:

在我以模态方式呈现的ViewController中,我这样做了:

In a ViewController, which I presented modally, I did this:

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

这曾经有效,但没有更长的作品。隐藏此视图控制器的状态栏的最佳方法是什么?

This used to work, but it no longer works. What's the best way to hide the status bar only for this view controller?

对于 Swift 3 & Swift 4 它已更改为覆盖此变量:

For Swift 3 & Swift 4 it has changed to overriding a variable like this:

override var prefersStatusBarHidden: Bool {
  return true
}

如果你想更新状态一旦视图控制器已经显示,您需要调用:

If you want to "Update" the state once the view controller is already being displayed, you will need to call:

setNeedsStatusBarAppearanceUpdate()

请参阅文档