当一个视图被删除有约束,会发生什么 [英] What happens with constraints when a view is removed
问题描述
我的问题很简单,但我无法找到的文档中的任何信息。
The question I have is simple but I couldn't find any information in the documentation.
在一个视图从视图层次结构中删除(或移动到另一个视图)与布局约束,会发生什么?
What happens with layout constraints when a view is removed from the view hierarchy (or moved to another view)?
例如,让我们的容器 C
与子视图 A
和 B
。集装箱 C
持有一定的制约。然后我们调用 [A removeFromSuperview]
。与 A
?
For example, let's have container C
with subviews A
and B
. Container C
holds some constraints. Then we call [A removeFromSuperview]
. What happens with the constraints for A
?
如果我们添加 A
则正好 C
一遍吗?
What then happens if we add A
to C
again?
推荐答案
约束被删除。如果再次加A,你将不得不做出新的约束,或者如果保存约束你删除之前,你可以添加他们回来。当我做这样的事情,我保存这样的约束视图称为视图1:
The constraints are removed. If you add A again, you will have to make new constraints for it, or if you save the constraints before you remove A, you can add them back. When I do something like this, I save the constraints like this for a view called view1:
self.portraitConstraints = [NSMutableArray new];
for (NSLayoutConstraint *con in self.view.constraints) {
if (con.firstItem == self.view1 || con.secondItem == self.view1) {
[self.portraitConstraints addObject:con];
}
}
这篇关于当一个视图被删除有约束,会发生什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!