ios - preferredStatusBarStyle 未在 iOS 13 和其他系统中调用

标签 ios swift statusbar ios13

我有多个 UITabBar在我的应用程序和一些 ViewController有白色状态栏和一些 ViewController有黑色状态栏。

我的 info.plistView controller-based status bar appearanceYES
我的 Viewcontroller 有以下代码。

override var preferredStatusBarStyle: UIStatusBarStyle {
    return .default //or return . lightContent
}

但是 preferredStatusBarStyle永远不会被调用。

我还在我的 Controller 中写了下面的行 viewDidLoad但仍然没有被调用。
self.setNeedsStatusBarAppearanceUpdate()
我也换了 controller-based status bar appearanceYES && NO多次检查但对我没有任何帮助。

我也尝试过以下解决方案和其他 stackoverflow 答案,但没有任何帮助。

preferredStatusBarStyle not respecting on iOS 13

preferredStatusBarStyle var not working in iOS12?

编辑

我尝试了下面的代码,它返回 topViewController它会调用 preferredStatusBarStyleViewController
extension UINavigationController {
    override open var childForStatusBarStyle: UIViewController? {
        return topViewController
    }
}

所以一旦topViewController发现它会打电话preferredStatusBarStyle那个特别的 ViewController .

但问题是它没有在内部被调用 UITabBarController -> UINavigationController -> UIViewController .

要求

我有 2 个不同的 TabBarController .

第一 TabBarController statusBarStyle 是 .lightContent .

第二 TabBarController statusBarStyle 是 .lightContent.default在不同的 Controller 中。

当我更改为第二个 TabBarController 时,它会调用 preferredStatusBarStyle第二个 TabBarController和所有 ViewController statusBarStyle 去 .default但我的一些 Controller statusBarStyle 想要成为 .ligthContent
我怎样才能做到这一点?

任何帮助将不胜感激。

谢谢

最佳答案

这与 iOS 13 无关。你只是规则错了。
在导航 Controller 的情况下,状态栏的颜色不是由 View Controller 的 preferredStatusBarStyle 决定的。
令人惊讶的是,它是由导航栏的 barStyle 决定的。要获取状态栏文本,请说(在您的 View Controller 中):

self.navigationController?.navigationBar.barStyle = .black

关于ios - preferredStatusBarStyle 未在 iOS 13 和其他系统中调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59577879/

相关文章:

ipad - 在 iPad 上绘制 2D Sprite 的 GL_BLEND 问题

ios 快速解析 : Saving to keychain and print out data from keychain and do a login

objective-c - 在 Swift 中使用 Objective-C 函数,该函数接受对变量的引用

ios - 考虑到我设置的约束,为什么 UILabel 的文本没有被截断?

swift - iOS 13 导航栏.barStyle

Android - Fragment 中 CoordinatorLayout 中状态栏下的工具栏

iphone - UIScrollView ContentOffset 未到达屏幕边缘

ios - 获取相对于 SKEffectNode 屏幕的绝对位置,因为它被 SKWarpGeometryGrid 扭曲

ios - 平移手势后将 View 返回到原始位置,swift

ios - 在状态栏设置为隐藏时检测点击状态栏