gpt4 book ai didi

ios - 什么是 _UIBaselineLayoutStrut

转载 作者:行者123 更新时间:2023-11-28 12:06:18 25 4
gpt4 key购买 nike

在我的 ios 项目(用 swift 编写)上使用自动布局时,出现错误 AMBIGUOUS LAYOUT for _UIBaselineLayoutStrut。我无法弄清楚这是来自哪个 ui 元素。任何人对我如何追踪它或这可能是什么有任何建议?

最佳答案

根据runtime headers ,它是从(也是私有(private)的)UITextFieldLabel 派生的私有(private) UIKit 类。

您可能有一个 UITextField 和一些涉及其基线的约束。在这种情况下,您可以通过列出影响文本字段垂直布局的约束来发现 _UIBaselineLayoutStrut(在自动布局指南中查看更多 debugging tips):

(lldb) po myTextField.constraintsAffectingLayout(for: .vertical)

示例输出(参见#0 和#3):

▿ 6 elements
- 0 : <NSContentSizeLayoutConstraint:0x6000000b3aa0 _UIBaselineLayoutStrut:0x7fb249616990.height == 21 Hug:1000 CompressionResistance:1000 (active)>
- 1 : <NSContentSizeLayoutConstraint:0x6000000b3da0 UITextField:0x7fb24b00c000.height == 30 Hug:250 CompressionResistance:750 (active)>
- 2 : <NSLayoutConstraint:0x60400009ad60 UITextField:0x7fb24b00c000.lastBaseline == UIView:0x7fb249616170.centerY (active)>
- 3 : <NSLayoutConstraint:0x6000000915d0 V:|-(4)-[_UIBaselineLayoutStrut:0x7fb249616990] (active, names: '|':UITextField:0x7fb24b00c000 )>
- 4 : <NSLayoutConstraint:0x60000008b680 'UIView-Encapsulated-Layout-Height' UIView:0x7fb249616170.height == 568 (active)>
- 5 : <NSAutoresizingMaskLayoutConstraint:0x600000091080 h=-&- v=-&- 'UIView-Encapsulated-Layout-Top' UIView:0x7fb249616170.minY == 0 (active, names: '|':UIWindow:0x7fb24960ef60 )>

将其(粗略地)视为一个辅助 View ,当您将其约束到文本字段的基线时,约束将实际应用到该 View 。

_UIBaselineLayoutStrut 的模糊布局反过来意味着自动布局没有足够的信息来根据您提供的约束为您的 UITextField 计算出准确的位置。 Ambiguous Layouts连同上面提到的调试提示,应该是一个很好的调查起点。

关于ios - 什么是 _UIBaselineLayoutStrut,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49307627/

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