首页 文章

后退按钮后隐藏的导航栏

提问于
浏览
0

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

我有一个嵌入在带有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 tap动作转到view2并在故事板中而不是在代码中执行segue,则不会出现问题 .

有什么想法解决它吗?

2 回答

  • 0

    我刚拿到它!

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

    放置此代码:

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

相关问题