gpt4 book ai didi

ios - 不需要的 "Sticky"返回后在导航栏上着色

转载 作者:行者123 更新时间:2023-11-30 11:35:00 25 4
gpt4 key购买 nike

从 VC2 单击后退后,我的 VC1 导航栏下方出现粘稠的纯色。启动时,只有在单击后退后,我才看到这种粘性。如何去除这种粘性?图像本身。

VC1 中的导航栏没有粘性,即当我向下拉导航栏时,白色背景会拉伸(stretch):

NavBar in VC1 without tint

VC1 中的导航栏具有粘性,即当我向下拉导航栏时,白色背景不会拉伸(stretch) NavBar in VC1 with stickiness after clicking 'back' from VC2

到目前为止的代码:

//At viewDidLoad() in VC1
navigationController?.navigationBar.barTintColor = .white


//At viewDidLoad() in VC2

navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
navigationController?.navigationBar.isTranslucent = true
navigationController?.view.backgroundColor = .clear
navigationController?.navigationBar.barTintColor = .white
navigationController?.navigationBar.shadowImage = UIImage()

我在VC2中这样实现是因为我有一个mapView,我想将它一直扩展到状态栏。

有人可以建议我如何去除粘性色调,以便当我拉下 VC1 中的导航栏时白色色调会拉伸(stretch)吗?

最佳答案

之所以出现在后退按钮上,是因为在VC2中对导航栏所做的更改也适用于VC1的导航栏。

您可以尝试通过将代码移至 viewWillAppear 方法并将以下几行添加到 VC1 代码中来修复此问题:

var navBarBackgroundImage: UIImage?
var navBarShadowImage: UIImage?

override func viewDidLoad() {
super.viewDidLoad()
navBarBackgroundImage = navigationController?.navigationBar.backgroundImage(for: .default)
navBarShadowImage = navigationController?.navigationBar.shadowImage
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if let navBarBackgroundImage = navBarBackgroundImage {
navigationController?.navigationBar.setBackgroundImage(navBarBackgroundImage, for: .default)
}
if let navBarShadowImage = navBarShadowImage {
navigationController?.navigationBar.shadowImage = navBarShadowImage
}
navigationController?.navigationBar.isTranslucent = false
navigationController?.navigationBar.barTintColor = .white
}

VC2:

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
navigationController?.navigationBar.isTranslucent = true
navigationController?.view.backgroundColor = .clear
navigationController?.navigationBar.barTintColor = .white
navigationController?.navigationBar.shadowImage = UIImage()
}

关于ios - 不需要的 "Sticky"返回后在导航栏上着色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49856816/

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