gpt4 book ai didi

ios - UINavigationBar isTranslucent false 但保持透明度

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

我目前设置了一个项目,在注册期间我使用 UINavigationController 来管理 View Controller ,作为设计的一部分,我使用以下代码将 UINavigationBar 设置为透明:

    let navBar: UINavigationBar! =  self.navigationController?.navigationBar
navBar.setBackgroundImage(UIImage(), for: UIBarMetrics.default)
navBar.shadowImage = UIImage()
navBar.backgroundColor = UIColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 0.0)
navBar.tintColor = UIColor.white
navBar.barTintColor = UIColor.clear

这允许我使用导航 Controller 的层次结构来管理向后/向前移动,并且工作正常,除了当我显示 View Controller 时,我拥有的任何 View (通过自动布局设置)都会执行“跳跃”运动进入正确的位置(就像 this question 的视频 https://vid.me/9kB5 )。一些搜索让我尝试了以下 2 种解决方案

1.) 在 Storyboard View Controller 中取消选中“延伸边缘 - 在顶部栏下”
2.) 将导航栏的半透明度设置为 false

navBar.isTranslucent = false

这解决了跳跃运动并导致 View 在加载时就位,但问题是导航栏现在变成了 barTintColor(对于 UIColor.clear 最终变成黑色)。看来我无法同时保持透明度和半透明。 Stack 上很多类似的问题都有设置颜色且不透明的导航栏。

我想到的下一个方法是我必须摆脱 UINavigationController,而是在每个注册 View Controller 上实现后退按钮,但我希​​望尝试使用导航 Controller 来解决这个问题。

是否可以将 UINavigationBar 的半透明度设置为 false 但保持透明度?

编辑:这是使用 isTransluscent = false 代码时导航栏的外观图片: enter image description here

最佳答案

尝试更改“alpha”属性。确保您对导航栏所做的所有操作都在主线程上进行。

解决方案2:您可以为导航栏背景设置特定的UIImage。

关于ios - UINavigationBar isTranslucent false 但保持透明度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39987909/

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