后退按钮后隐藏的导航栏

Navigation bar hidden after back button

单击后退按钮后出现问题。

我将第一个视图嵌入到带有 imageView 的 NavigationController 中。 使用以下代码自定义导航栏:

override func viewDidLoad() {
    super.viewDidLoad()

    // color the navigation bar and text
    self.navigationController?.navigationBar.barTintColor = UIColor(red: 0, green: 0.24, blue: 0.45, alpha: 1)
    self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName : UIColor.whiteColor()]

当用户点击 imageView 时,将执行以下代码:

self.performSegueWithIdentifier("view2", sender: self)

这是一个 show(push) segue。

当用户在视图 2 中点击 Back button 时,它 returns 首先显示但导航栏消失了!

我认为它被某些东西掩盖了,因为我可以在调试期间通过单击 Debug View Hierarchy 看到它。

最后一点,如果我用一个简单的条形按钮替换 imageView 点击操作以转到 view2,并在情节提要中而不是在代码中执行 segue,则问题不会出现。

有解决办法吗?

放置此代码:

// color the navigation bar and text
self.navigationController?.navigationBar.barTintColor = UIColor(red: 0, green: 0.24, blue: 0.45, alpha: 1)
self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName : UIColor.whiteColor()]

在 viewWillAppear 中

刚收到!

我意识到在 view2 中,我使用代码使导航栏半透明:

override func viewDidLoad() {
    super.viewDidLoad()

    // Set the navigation bar translucent
    navigationController?.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: UIBarMetrics.Default)
    navigationController?.navigationBar.shadowImage = UIImage()
    navigationController?.navigationBar.translucent = true

所以要修复该错误,只需在视图消失之前删除半透明属性即可:

override func viewWillDisappear(animated: Bool) {
    navigationController?.navigationBar.translucent = false

希望有一天能对某人有所帮助:)