尝试在模态视图中隐藏状态栏。
已经检查了几种方法:
override func prefersStatusBarHidden() -> Bool {
return true
}
with / without self.setNeedsStatusBarAppearanceUpdate()
还有
UIApplication.sharedApplication().setStatusBarHidden(true, withAnimation: .Fade)
但在 iOS 9 中贬值
这适用于全屏显示(模式 segue 显示选项),但请注意全屏显示这是我的设置。
如果你有任何想法..
最佳答案
对于 View Controller 的非全屏显示,您需要使用modalPresentationCapturesStatusBarAppearance
属性。
例如
toViewController.modalTransitionStyle = .coverVertical
toViewController.modalPresentationStyle = .overFullScreen
toViewController.modalPresentationCapturesStatusBarAppearance = true
fromViewController.present(toViewController,
animated: true,
completion: nil)
对于 View Controller 的全屏展示,您需要:
- 设置新 VC 的
modalPresentationStyle
。 - 在新的 VC 中覆盖
prefersStatusBarHidden
- 将您的应用 plist
UIViewControllerBasedStatusBarAppearance
值设置为 YES
例如
toViewController.modalTransitionStyle = .coverVertical
toViewController.modalPresentationStyle = .fullScreen
fromViewController.present(toViewController,
animated: true,
completion: nil)
(是的,iOS 中的状态栏设置非常糟糕。难怪 Stack Overflow 有这么多关于这个主题的问题,以及这么多不同的答案。)
关于ios - 隐藏在模态视图中的状态栏(在全屏演示中),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33546589/