gpt4 book ai didi

iOS statusBar 背景在转换后变黑

转载 作者:可可西里 更新时间:2023-11-01 01:57:31 28 4
gpt4 key购买 nike

我正在从 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

但是我在转换时得到了这个奇怪的黑色状态栏:

strange black line on top enter image description here

Here is a sample project

这是预期的过渡: enter image description here

最佳答案

你能试试下面吗,

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)
}

关于iOS statusBar 背景在转换后变黑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50721196/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com