gpt4 book ai didi

ios - 如何在透明 UINavigationBar 和带背景颜色的 UINavigationBar 之间切换

转载 作者:行者123 更新时间:2023-11-29 05:55:11 27 4
gpt4 key购买 nike

我有一些UIViewControllers,它们都有纯背景颜色。但是,在用户的个人资料上,我想在背景上显示模糊的个人资料图像,因此我需要一个透明的 UINavigationBar。这很好用。我的做法如下:

我所有的UIViewControllers都设置为具有透明的UINavigationBar,如下所示:

    navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
navigationController?.navigationBar.shadowImage = UIImage()
navigationController?.navigationBar.isTranslucent = true

然后,我只需创建一个矩形 UIView 并将所有边缘固定到 UINavigationBar 所在的位置,即可添加一个“假”栏,从而获得相同的外观,但允许我让个人资料页面透明。但是,我现在遇到一种情况,我需要使用“真正的”UINavigationBar,因为在我当前的方法中,当我显示键盘和动画 view.frame.origin.y code> 为了使屏幕向上移动,它会“越过”这个假的 UINavigationBar

因此,我在此 viewController 中设置了 UINavigationBarbarTintColor 属性。当我第一次进入此 View 然后进入个人资料页面时出现问题:它仍然是相同的纯色。当我启动后直接进入个人资料页面时,不会出现该问题。

This is the desired result, which I can see when I go directly to a profile page.

This is what a normal viewController looks like, with the "fake" UINavigationBar

And this is the error. This happens when I first go to the viewController with the barTintColor set, and then to a profile page

关于如何解决这个问题有什么建议吗?我尝试过使用 barTintColor 设置来“重置”viewController 的 viewWillDisappear 中的 UINavigationBar 属性,但这不起作用:

override func viewWillDisappear(_ animated: Bool) {

super.viewWillDisappear(animated)
navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
navigationController?.navigationBar.shadowImage = UIImage()
navigationController?.navigationBar.isTranslucent = true
navigationController?.navigationBar.barTintColor = nil

}

可能有用:我大部分时间都使用推送转换(肯定是在相关的 viewController 之间)。仅使用 Present 来显示弹出窗口或类似内容。一切都在代码中 - 没有 Storyboard。

任何帮助将不胜感激!

最佳答案

您可以使用 Present 代替 Push。所以你可以有两个不同的导航栏。

关于ios - 如何在透明 UINavigationBar 和带背景颜色的 UINavigationBar 之间切换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55241938/

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