返回上一个VC后,导航栏会发生变化

时间:2017-02-21 17:29:53

标签: ios swift swift3 uinavigationcontroller uinavigationbar

我的导航栏样式存在一些问题。让我们说我有两个视图控制器。

VC 1有一个带有白色文字的橙色条,我已按如下方式设置:

   func stylingStuffs(){
    self.navigationController?.navigationBar.barTintColor = UIColor(red: 0.94, green: 0.38, blue: 0.24, alpha: 1)
    self.navigationController?.navigationBar.backgroundColor = UIColor(red: 0.94, green: 0.38, blue: 0.24, alpha: 1)
    self.navigationController?.navigationBar.tintColor = UIColor.white
    self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName : UIColor.white]
    self.navigationController?.navigationBar.isTranslucent = false
    UIApplication.shared.statusBarStyle = .lightContent
}

VC 2有一个透明的导航栏,其代码为:

func stylingStuffs(){
    navigationController?.setNavigationBarHidden(false, animated: true)
    navigationController?.navigationBar.setBackgroundImage(UIImage(), for: UIBarMetrics.default)
    self.navigationController?.navigationBar.barTintColor = UIColor(red: 0.94, green: 0.38, blue: 0.24, alpha: 0)
    self.navigationController?.navigationBar.backgroundColor = UIColor(red: 0.94, green: 0.38, blue: 0.24, alpha: 0)
    navigationController?.navigationBar.shadowImage = UIImage()
    navigationController?.navigationBar.isTranslucent = true
    navigationController?.navigationBar.tintColor = UIColor.white
    self.navigationController?.navigationBar.barStyle = .default
    UIApplication.shared.statusBarStyle = .lightContent
}

当我从VC1-> VC2导航时,一切正常,当我从VC2-> VC1导航时,VC1的导航栏现在是白色/透明的,还有状态栏。

如何修复此问题或者我想在返回VC1时重置样式?

先谢谢!

1 个答案:

答案 0 :(得分:0)

首先查看 VC 1 控制器viewDidAppear致电stylingStuffs()

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

    stylingStuffs()
}

@rmaddy 评论

  

您很困惑,因为实际上只有一个导航栏。它是一个导航控制器的一部分,两个视图控制器都在

因此需要重置VC 1的导航栏样式