问题描述
我在 UINavigationController
中有三个viewControllers。在第二个我需要隐藏导航栏而不是后退按钮和其他栏按钮。出于这个原因,我不能使用 isNavigationBarHidden = true
目前我正在按如下方式处理上述内容:
I have three viewControllers in a UINavigationController
. In the second one I need to hide the navigation bar but not the back button and other bar button. For this reason I can't use isNavigationBarHidden = true
Currently I am handling the above as follows :
第一个viewController:
First viewController :
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.navigationController?.navigationBar.barTintColor = Constants.kThemeRedColor
self.navigationController?.navigationBar.tintColor = UIColor.white
self.navigationController?.navigationBar.barStyle = .black
self.navigationController?.navigationBar.isTranslucent = false
}
第二个viewController(隐藏导航条):
Second viewController (hide only nav bar) :
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: UIBarMetrics.default)
self.navigationController?.navigationBar.shadowImage = UIImage()
self.navigationController?.navigationBar.isTranslucent = true
self.navigationController?.view.backgroundColor = UIColor.clear
}
这里的问题是,当我从第一个ViewController导航到第一个ViewController时,在第一个viewController消失并且分别出现的时间很短,我看到了一个黑色的导航栏。我知道这是因为在第二个viewController中编写的代码。但我没有任何其他解决方案。附上截图:
The issue here is that when I navigate from and to the firstViewController, for a very short duration when the 1st viewController is disappearing and appearing respectively, I see a black nav bar on it. I know this is because of the code written in 2nd viewController. But I don't have any other close solution of doing this. Attaching a screenshot :
第一个viewController(应该如何):
第二个viewController:
第一个viewController(黑色导航条持续时间很短):
推荐答案
在 First viewController
中,还设置 backgroundImage
和 shadowImage
navigationBar
as nil
,即
In First viewController
, also set the backgroundImage
and shadowImage
of navigationBar
as nil
, i.e.
class FirstVC: UIViewController
{
override func viewWillAppear(_ animated: Bool)
{
super.viewWillAppear(animated)
self.navigationController?.navigationBar.isTranslucent = true
self.navigationController?.navigationBar.setBackgroundImage(nil, for: UIBarMetrics.default)
self.navigationController?.navigationBar.shadowImage = nil
self.navigationController?.navigationBar.barTintColor = .red
self.navigationController?.navigationBar.tintColor = UIColor.white
self.navigationController?.navigationBar.barStyle = .black
}
}
class SecondVC: UIViewController
{
override func viewWillAppear(_ animated: Bool)
{
super.viewWillAppear(animated)
self.navigationController?.navigationBar.isTranslucent = true
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: UIBarMetrics.default)
self.navigationController?.view.backgroundColor = UIColor.clear
self.navigationController?.navigationBar.shadowImage = UIImage()
}
}
这篇关于UINavigationController仅隐藏navigationBar - 返回动画问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!