我有一个 UIView,其中包含多个具有自己的约束的 UIView 子视图。如何删除子视图的约束?
//only removes the constraints on self.view
[self.view removeConstraints:self.view.constraints];
//I get warning: Incompatible pointer types sending 'NSArray *' to parameter of type 'NSLayoutConstraint'
[self.subview1 removeConstraints:self.subview1.constraints];
试试这个代码:
for (NSLayoutConstraint *constraint in self.view.constraints) {
if (constraint.firstItem == self.subview1 || constraint.secondItem == self.subview1) {
[self.view removeConstraint:constraint];
}
}
基本上,这会迭代分配给的所有约束self.view
并检查是否self.subview1
参与约束。如果是这样,该约束就会被取消。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)