在导航控制器中时,将忽略视图控制器的首选状态栏样式 [英] Preferred status bar style of view controller is ignored when in navigation controller

查看:61
本文介绍了在导航控制器中时,将忽略视图控制器的首选状态栏样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写具有多个视图的iOS应用.我将应用程序设置为使用基于ViewController的状态栏样式,这使我可以使用以下代码

I'm writing an iOS App with multiple views. I've set the App to use ViewController-based status bar style, which allows me to use the following code

override var preferredStatusBarStyle: UIStatusBarStyle {
    return .lightContent
} 

效果与预期一样.

但是随后我将视图嵌入导航控制器中,并将BarButtonItem与showSegue连接起来.从那以后,视图的ViewController切换为忽略样式设置,并显示默认的黑色状态栏.

But then I've embedded the views in a navigation controller and connected a BarButtonItem with a showSegue. Since then the ViewController of the view switched to ignores the style settings and shows the default black status bar.

推荐答案

当您位于不会被调用的导航控制器中时.导航控制器的preferredStatusBarStyle将被调用.尝试将其与您的代码一起使用:

When you're in a navigation controller that will not get called. The navigation controller's preferredStatusBarStyle will be called. Try this along with your code:

extension UINavigationController {

   open override var preferredStatusBarStyle: UIStatusBarStyle {
      return topViewController?.preferredStatusBarStyle ?? .default
   }
}

这篇关于在导航控制器中时,将忽略视图控制器的首选状态栏样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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