xcode 隐藏视图控制器的导航栏

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/47150880/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 10:25:01  来源:igfitidea点击:

Hide Navigation Bar for a View Controller

iosswiftxcodeswift4xcode9

提问by Jonathan Solorzano

I've tried to hide the navigation controller for a single view controller with no luck, the navigation bar is hidden for the first vc, but it's not displaying for the second vc.

我试图隐藏单个视图控制器的导航控制器,但没有运气,第一个 vc 隐藏了导航栏,但第二个 vc 没有显示它。

Here's the code I've used in the first vc:

这是我在第一个 vc 中使用的代码:

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    // Hide the Navigation Bar
    self.navigationController?.setNavigationBarHidden(true, animated: animated)
}

override func viewWillDisappear(_ animated: Bool) {
    super.viewWillDisappear(animated)

    // Show the Navigation Bar
    self.navigationController?.setNavigationBarHidden(false, animated: animated)
}

What's changed in swift 4? That code worked in swift 3...

swift 4 有什么变化?该代码在 swift 3 中有效......

回答by Dilip Tiwari

Use code:- Swift 4

使用代码:- Swift 4

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(true)
// Hide the Navigation Bar
        self.navigationController?.setNavigationBarHidden(true, animated: true)
    }

override func viewWillDisappear(_ animated: Bool) {
    super.viewWillDisappear(true)
// Show the Navigation Bar
        self.navigationController?.setNavigationBarHidden(false, animated: false)
    }

I think you have done mistake in animated: true

我认为你做错了 animated: true