我正在从UINavigationController内的VC1推送到VC2。 VC2有一个透明的navigationBar。
在VC2中的viewDidLoad中:
self.navigationController?.navigationBar.isTranslucent = true
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
self.navigationController?.navigationBar.barTintColor = .clear
self.navigationController?.navigationBar.backgroundColor = .clear
当我按下后退按钮时我想恢复导航栏(绿色),所以在viewWillDissapear里面我有以下内容:
self.navigationController?.navigationBar.isTranslucent = false
self.navigationController?.navigationBar.setBackgroundImage(nil, for: .default)
self.navigationController?.navigationBar.barTintColor = .green
self.navigationController?.navigationBar.backgroundColor = .green
但是我在过渡期间得到了这个奇怪的黑色状态栏:
答案 0 :(得分:1)
你能在下面试试吗,
override func viewDidLoad() {
super.viewDidLoad()
UINavigationBar.appearance().backgroundColor = .clear
UINavigationBar.appearance().barTintColor = .clear
self.navigationController?.navigationBar.shadowImage = UIImage()
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
}
和
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
UINavigationBar.appearance().backgroundColor = .green
UINavigationBar.appearance().barTintColor = .green
self.navigationController?.navigationBar.setBackgroundImage(nil, for: .default)
}