首页 > 解决方案 > Fullscreen modal makes navigationBar.barStyle not working properly

问题描述

I've uploaded a minimum demo app here: Demo

The problem I am facing is triggered in a very particular flow as below: In the demo app, I have a Level2 viewController with

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    self.navigationController?.navigationBar.barStyle = .default
    self.navigationController?.navigationBar.tintColor = .blue
}

and a Level 3 viewController pushed from L2 viewController with

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    self.navigationController?.navigationBar.barStyle = .black
    self.navigationController?.navigationBar.tintColor = .white
}

If the navigation is just between L2 and L3, Example flow: rootViewController > L2 > L3 > L2

the status bar style and the bar style always work as expected: Darkmode style in L3 and Lightmode style in L2.

The problem comes only after a modal is presented from L3 viewController with modalPresentationStyle = .fullScreen

The navigation bar on L2 stays grey, seems navigationBar.barStyle = .default in viewWillAppear doesn't work any more

Example flow: rootViewController > L2 > L3 > full screen modal > L3 > L2

Does anyone know is it possible to make L2 navigation bar style work correctly in this specific flow? Or is that bug? Any workaround?

标签: iosswiftxcodeuinavigationbar

解决方案


推荐阅读