Ios 如何使用DSL更新约束?
我正在代码中创建自动布局约束,在Ios 如何使用DSL更新约束?,ios,swift,nslayoutconstraint,Ios,Swift,Nslayoutconstraint,我正在代码中创建自动布局约束,在updateConstraints中使用: 我在控制台日志中获得以下内容: Unable to simultaneously satisfy constraints. Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out
updateConstraints
中使用:
我在控制台日志中获得以下内容:
Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<NSLayoutConstraint:0x7f8eabc684e0 Demo.View1:0x7f8eabc34680.top == Demo.View2:0x7f8eabc3ef20.bottom + 10>",
"<MASLayoutConstraint:0x7f8eabc39420 Demo.View1:0x7f8eabc34680.top == Demo.View2:0x7f8eabc3ef20.bottom + 40>"
)
Will attempt to recover by breaking constraint
<MASLayoutConstraint:0x7f8eabc39420 Demo.View1:0x7f8eabc34680.top == Demo.View2:0x7f8eabc3ef20.bottom + 40>
无法同时满足约束。
可能下面列表中至少有一个约束是您不想要的。试着这样做:(1)看看每个约束,试着找出你不期望的约束;(2) 找到添加了不需要的约束的代码,然后修复它。(注意:如果您看到不理解的NSAutoresizingMaskLayoutConstraints,请参阅UIView属性TranslatesAutoResizingMaskToConstraints的文档)
(
"",
""
)
将尝试通过打破约束进行恢复
为什么它没有更新约束
更新:
顺便说一句:我正在使用故事板。这里的错误消息给了我很好的建议 可能以下列表中至少有一个约束是 你不会想要的。尝试以下方法:(1)查看每个约束并尝试 找出你不期望的;(2) 查找添加了 一个或多个不需要的约束,然后修复它 并有用地打印出来
"<NSLayoutConstraint:0x7f8eabc684e0 Demo.View1:0x7f8eabc34680.top == Demo.View2:0x7f8eabc3ef20.bottom + 10>"
"<MASLayoutConstraint:0x7f8eabc39420 Demo.View1:0x7f8eabc34680.top == Demo.View2:0x7f8eabc3ef20.bottom + 40>"
“”
""
请注意两个约束和对象引用之间的相似性
view1
的顶部应低于view2
的底部10或40。不可能两者都是那么哪一个呢?当您使用massy
时,我怀疑这就是您想要的MASLayoutConstraint
约束
找出NSLayoutConstraint
的来源。这不是一个自动调整大小的一个,因为他们有蠕动在他们。所以要么你把它放在你的代码里,要么它来自一个XIB/故事板
您可以在Xcode中使用regex find,如果它是前者,那么就更容易了。我可以试试这个
点击“搜索”图标查看披露。您可以插入各种图案
我可以用这个作为开始
您没有向我们展示您的约束条件,因此很难判断问题出在哪里 我不知道为什么,但不能使用相对值(如multipledby)更新约束。您可以做的是将约束更新为常量。以及相对于屏幕大小可以计算的常数。像这样:
_height_y = -self.view.frame.size.height*0.25;
[_phoneField updateConstraints:^(MASConstraintMaker *make) {
make.baseline.equalTo(self.view.centerY).with.offset(_height_y);
}];
NSLayoutConstraint(10)来自故事板。