gpt4 book ai didi

ios - 如何在 objective c 中启用自动布局时增加 uiview 的高度

转载 作者:行者123 更新时间:2023-11-28 18:17:00 24 4
gpt4 key购买 nike

我尝试使用以下代码在运行时以编程方式关闭界面构建器中特定 subview 的自动布局。

[view removeConstraints:view.constraints];

某处有人建议这样做:

If you need to change the height of a view with auto layout active, you'll need to create an IBOutlet for your height constraint and modify that at runtime, i.e.:

@IBOutlet weak var heightConstraint: NSLayoutConstraint!
self.heightConstraint.constant = 200

但我不明白这是什么意思。

最佳答案

你必须添加:

[self layoutIfNeeded];

更改高度限制后添加到您的代码中。它将刷新 View 和约束。它只是意味着您可以将其保留在您的 View 中并创建一个约束来动态更改高度,而不是删除自动布局。

可以关注这个tutorial了解自动布局的工作原理

关于ios - 如何在 objective c 中启用自动布局时增加 uiview 的高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34672643/

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