首页 文章

ios swift - 当返回隐藏导航栏的屏幕时,导航项目背景变为黑色

提问于
浏览
6

我认为显示屏幕截图有助于更好地理解问题 .

所以上下文如下:

我在导航控制器中,在应用程序的设置屏幕上(有一个导航项),当我们点击后退按钮时,我们回到应用程序的主屏幕(为此我隐藏了导航在主屏幕的viewWillAppear中,因为我正在构建自定义 Headers 视图 .

当我点击后退按钮时,导航栏立即消失,我看到一个黑色矩形,直到显示主屏幕的动画完成 .

你知道我怎么能避免出现这个黑色矩形吗?

希望这些问题有意义 .

截图

Here is the initial settings screen:

enter image description here

When we tape on the back button, this happens... help :D

我知道这段代码最有可能导致错误,但我绝对需要在上一个屏幕上隐藏navigationBar .

覆盖func viewWillAppear(_ animated:Bool){

navigationController?.isNavigationBarHidden = true

}

enter image description here

2 回答

  • 5

    For Swift3.0

    在First ViewController中添加以下代码

    override func viewWillAppear(_ animated: Bool) {
         super.viewWillAppear(true)
         self.navigationController?.setNavigationBarHidden(true, animated: true)
        }
    

    在Second ViewController中添加以下代码

    func backButtonPressed() {
            self.navigationController?.setNavigationBarHidden(false, animated: false)
            self.navigationController?.popViewController(animated: true)
        }
    
  • 11

    您是否尝试过隐藏导航栏 setNavigationBarHidden(_ hidden: Bool, animated: Bool) 的动画方法?

相关问题