在一个ViewController上隐藏iOS NavigationBar-发生奇怪的动画

问题描述

我在Swift 5中有一个用于iOS应用程序的标准UINavigationController,在其中我想将导航栏隐藏在堆栈中 first ViewController上。

我的故事板本质上是:

UINavigationController-> ViewControllerA-> ViewControllerB

具有简单的Show segues。

ViewControllerA 中,我输入了以下内容

override func viewWillAppear(_ animated: Bool) {
  super.viewWillAppear(animated)
  self.navigationController?.navigationBar.isHidden = true
}

ViewControllerB 中,我输入了以下内容

override func viewWillAppear(_ animated: Bool) {
  super.viewWillAppear(animated)
  self.navigationController?.navigationBar.isHidden = false
}

但是在模拟器中,从A-> B的过渡呈现出这种怪异的现象,例如“窥探”动画,我无法弄清楚如何摆脱它。

有什么想法吗?预先谢谢你!

Odd animation in ViewController transition

解决方法

还有另一种隐藏导航栏的方法,您可以在其中将“动画”设置为false,这可能会对您有所帮助。

self.navigationController?.setNavigationBarHidden(true,animated: false)