后退按钮后隐藏的导航栏

时间:2016-04-22 21:52:38

标签: ios swift uinavigationcontroller uinavigationbar segue

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

我在带有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。

当用户点击view2中的Back button时,它会返回第一个视图,但导航栏已消失!

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

最后一点,如果我将imageView点击操作替换为通过简单的条形按钮转到view2并在故事板中而不是在代码中执行segue,则不会出现问题。

有什么想法来解决它吗?

2 个答案:

答案 0 :(得分:1)

我刚刚得到它!

我意识到在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

希望有一天可以帮助某人:)

答案 1 :(得分:0)

放置此代码:

// 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

相关问题