gpt4 book ai didi

ios - topLayoutGuide 在导航 Controller 推送后移动

转载 作者:可可西里 更新时间:2023-11-01 00:49:59 25 4
gpt4 key购买 nike

我有一个简单的 View Controller 层次结构,其中一个 View Controller 使用 UINavigationController 显示。在 viewDidLoad 中,它设置了带有约束的 View 。在 View 完全可见之前(动画期间),topLayoutGuide 是状态栏,当 View 完全显示在屏幕上时,它变为 UINavigationBar 的底部。这会导致 View 跳跃。

删除“Extend Edges Under Top Bars”选项修复了这个问题,但使导航栏有一个不需要的灰色渐变,这只能通过设置导航栏的 backgroundColor 部分纠正。

有没有办法让 topLayoutGuide 即使在动画期间也能引用导航栏的底部?这以前有效,但不适用于 iOS 10 中的 Xcode 8.0。

最佳答案

通过注释掉大块代码,我在从 viewDidLoad() 调用的设置函数之一中找到了罪魁祸首。抱歉,我的问题没有包含足够的细节来解决它。以防将来有人看到此症状,这里是重现错误的代码:

override func viewDidLoad() {
super.viewDidLoad()
let label = UILabel(frame: CGRect.zero)
label.text = "Testing"
label.translatesAutoresizingMaskIntoConstraints = false
self.view.addSubview(label)
self.view.addConstraint(NSLayoutConstraint(item: label, attribute: .top, relatedBy: .equal, toItem: topLayoutGuide, attribute: .bottom, multiplier: 1, constant: 0))
self.view.layoutIfNeeded()
}

解决方案是删除 layoutIfNeeded() 调用。约束在 viewDidLoad() 后生效,在其中调用 layoutIfNeeded() 会暂时搞砸 topLayoutGuide

关于ios - topLayoutGuide 在导航 Controller 推送后移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40196907/

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