preferredStatusBarStyle在iOS 13上不适用 [英] preferredStatusBarStyle not respecting on iOS 13

查看:75
本文介绍了preferredStatusBarStyle在iOS 13上不适用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在模拟器中使用深色背景的单视图应用程序.这是一个包装在UINavigationController中的UIViewController.

I'm working in my simulator on a single view app with a dark background. It's a UIViewController wrapped in a UINavigationController.

在我的视图控制器中,我有override var preferredStatusBarStyle: UIStatusBarStyle { .lightContent }

In my view controller I have override var preferredStatusBarStyle: UIStatusBarStyle { .lightContent }

在我的info.plist中,我有View controller-based status bar appearance = YES

In my info.plist I have View controller-based status bar appearance = YES

但是,当我运行它时,它显示白色一秒钟,然后跳到显示黑色文本.

And yet when I run it it shows white for a second and then jumps to having black text.

这是怎么回事?有解决办法吗?

What's going on here? Is there a fix?

为确保没有任何作用,我已经尝试过.default.lightContent.darkContent

I've tried .default, .lightContent and .darkContent just to be sure, nothing works

推荐答案

我最近遇到了这个问题,这些扩展似乎可以解决此问题.

I recently ran into this problem and these extensions seemed to fix the issue.

extension UITabBarController {
    open override var childForStatusBarStyle: UIViewController? {
        return selectedViewController?.childForStatusBarStyle ?? selectedViewController
    }
}

extension UINavigationController {
    open override var childForStatusBarStyle: UIViewController? {
        return topViewController?.childForStatusBarStyle ?? topViewController
    }
}

我只是将它们放入名为UIViewController+StatusBar.swift的文件中,并将其包含在项目中.

I just put them into a file called UIViewController+StatusBar.swift and included it in the project.

这篇关于preferredStatusBarStyle在iOS 13上不适用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆