隐藏视图控制器的导航栏

时间:2017-11-07 05:55:07

标签: ios swift xcode swift4 xcode9

我试图隐藏单个视图控制器的导航控制器而没有运气,第一个vc隐藏了导航栏,但是第二个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)
}

swift 4有什么变化?该代码在swift 3中起作用......

1 个答案:

答案 0 :(得分:29)

使用代码: - Swift 4

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

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

我认为你在animated: true

中犯了错误