ios - 隐藏在模态视图中的状态栏(在全屏演示中)

标签 ios hidden statusbar modalviewcontroller

尝试在模态视图中隐藏状态栏。

已经检查了几种方法:

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 的全屏展示,您需要:

  1. 设置新 VC 的 modalPresentationStyle
  2. 在新的 VC 中覆盖 prefersStatusBarHidden
  3. 将您的应用 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/

相关文章:

ios - 如何导出在设备中为 Xcode 6 创建的文件?

android - Firebase 检查用户的身份验证状态/如果用户存在

javascript - 隐藏和整个表单元素

ios - 状态栏问题上方的小线

Java ftp下载状态栏

iphone - 从 plist 的数据加载给我错误顺序的值

安卓隐藏应用

hidden - SilverStripe 循环遍历隐藏页面

Android:如何更改 JellyBean 中的状态栏颜色(API 18)

ios - Swift Advanced - 在运行时设置扩展