7

I'm having troubles with the method setNavigationBarHidden, it doesn't seem to work properly on iOS 15.

I am currently working with this structure:

  1. A ViewController, which needs the navigationBar
  2. Another ViewController, pushed from the previous when I tap a UIButton, which doesn't need the navigationBar

On the previous versions of iOS, I simply called setNavigationBarHidden(true, animated: true) in the viewWillAppear method of the second ViewController and everything worked as expected but, from the new version of iOS, that doesn't occur correctly.

Now the navigationBar doesn't hide properly and, the only way I have to achieve the behavior I want, is by using the navigationBar.isHidden = true, which unfortunately leads me in a sloppy and not so smooth animation between the two controllers.

How can I solve this?

Libreage
  • 71
  • 3

2 Answers2

2

You need simply add

DispatchQueue.main.async {
navigationBar.isHidden = true
}
Ma_Ximus
  • 21
  • 2
-2
    /// 针对iOS15
    /// 适配导航栏隐藏
    static func configureNavgationBarStyle() {
        if #available(iOS 15.0, *) {
            let navigationBarAppearance = UINavigationBarAppearance()
            navigationBarAppearance.configureWithDefaultBackground()
            UINavigationBar.appearance().standardAppearance = navigationBarAppearance
            UINavigationBar.appearance().compactAppearance = navigationBarAppearance
            UINavigationBar.appearance().scrollEdgeAppearance = navigationBarAppearance
        }
    }

Calling this method in didFinishLaunchingWithOptions methods or other place you want, then the problem will disappear.

swift
  • 1