ios 如何触发对所有自动布局约束的更新?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20451609/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I trigger an update to all the autolayout constraints?
提问by János
I modified programmatically one autolayout constraint. It takes effect on one certain view, but other views that are bound with other constraints to that view, do not change their positions. Is there an "updateAllConstraints" method?
我以编程方式修改了一个自动布局约束。它对某个特定视图生效,但与该视图的其他约束绑定的其他视图不会改变它们的位置。是否有“ updateAllConstraints”方法?
采纳答案by János
The problem was that constrains were not set up properly, and in this case non of the setNeedsLayout or updateConstraintsIfNeeded can help.
问题是约束设置不正确,在这种情况下, setNeedsLayout 或 updateConstraintsIfNeeded 没有帮助。
回答by Andrea
Call those two methods on the view you want to be updated:
在要更新的视图上调用这两个方法:
-setNeedsLayout
-layoutIfNeeded
The first one says to the layout system that this view needs to be laid out, because it has some changes and, everything should be recalculated. The second force the layout system to be run now, layout system is triggered at specific times during runtime, with this method you are saying:"do it now".
第一个告诉布局系统这个视图需要布局,因为它有一些变化,一切都应该重新计算。第二个强制布局系统立即运行,布局系统在运行时的特定时间触发,使用此方法您说的是:“立即执行”。
回答by Hani Ibrahim
Yes There is a method on UIView called - (void)updateConstraintsIfNeeded
是的 UIView 上有一个方法叫做 - (void)updateConstraintsIfNeeded
However I don't think this is your problem
但是我不认为这是你的问题
回答by CrazyOne
Those of you that come across this topic, and are looking where to find this in the menus.
那些遇到这个主题的人,正在寻找在菜单中的位置。
Best I have found is:
我发现的最好的是:
Select the items that you want to "pop" back to your constraints
Top menu: Editor/Update Frames (or/) shortcut: command + option + =
选择要“弹出”回约束条件的项目
顶部菜单:编辑器/更新帧(或/)快捷方式:命令 + 选项 + =
Hopefully this helps
希望这会有所帮助