StatusBar样式的更新会有所延迟

问题描述 投票:1回答:1

我的项目中有2个StoryBoard,第一个ViewController中的所有storyBoard都属于.lightContent statusBarStyle,而第二个ViewController中的所有storyBoard都属于.default statusBarStyle

为此,我已完成以下步骤。

1. View controller-based status bar appearancetrue

2已在使用下面的代码。

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

当我从第一个storyBoard statusBar样式更改为rootController设置第二个ViewController storyBoard时,但我面临以下问题。

当我将第一个StoryBoard ViewController设置为rootController时,statusBarStyle会在几秒钟后更新。

不正确

enter image description here

几秒钟后

enter image description here

这是我的演示链接:https://www.dropbox.com/s/ijqg73zm1jxbokc/statusBarDemo.zip?dl=0

请指导我我所缺少的或实施不正确的内容。任何帮助将不胜感激。谢谢

swift statusbar ios-statusbar
1个回答
0
投票

InitialViewController:

var status = true
override var preferredStatusBarStyle: UIStatusBarStyle {
    return status ? .lightContent : .default
}

@IBAction func btnControllerTapped(_ sender: Any) {
    self.status = false
    self.preferredStatusBarStyle
    self.setNeedsStatusBarAppearanceUpdate()
    let storyboard = UIStoryboard(name:"Main", bundle: nil)
    let vc = storyboard.instantiateViewController(withIdentifier: "ViewController") as! ViewController
    let navigationController = UINavigationController(rootViewController: vc)
    appDelegate.window?.rootViewController = navigationController
}

我找到了这样的解决方案。它运作良好,但我不知道如何有用。

© www.soinside.com 2019 - 2024. All rights reserved.