gpt4 book ai didi

ios - 在导航栏上关闭半透明会使 View 不对齐

转载 作者:行者123 更新时间:2023-11-29 01:15:01 24 4
gpt4 key购买 nike

我创建了带导航栏的布局,并将导航栏半透明设置为不透明。我添加了这段代码:

var overlay : UIView? // This should be a class variable

overlay = UIView(frame: view.frame)
overlay!.backgroundColor = UIColor.blackColor()
overlay!.alpha = 0.8

view.addSubview(overlay!)

如果我理解正确,这应该会覆盖我的 View 。但它给了我这样的结果: enter image description here所以我认为这与我的观点不一致。知道如何解决这个问题吗?

最佳答案

Its is happening because view origin changes if you set translucent off. So Instead of using view.frame use view.bounds.

var overlay : UIView?

overlay = UIView(frame: view.bounds)
overlay!.backgroundColor = UIColor.blackColor()
overlay!.alpha = 0.8

view.addSubview(overlay!)

关于ios - 在导航栏上关闭半透明会使 View 不对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35289288/

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