【发布时间】:2015-12-10 15:00:44
【问题描述】:
但是当我尝试使用 nslayoutconstraint 时,
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.thing1 attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeadingMargin multiplier:1 constant:0]];
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.thing1 attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:[self topLayoutGuide] attribute:NSLayoutAttributeBottom multiplier:1 constant:0]];
}
我认为它应该与界面生成器中的约束相同。
但我收到了以下错误消息:
2015-12-10 22:59:01.320 Storyboard[7647:5116727] 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.
(
"<NSLayoutConstraint:0x12fd39a60 UIButton:0x12fd3c4f0'thing1'.leading == UIView:0x12fd3d590.leadingMargin>",
"<NSIBPrototypingLayoutConstraint:0x12fe48040 'IB auto generated at build time for view with fixed frame' H:|-(20)-[UIButton:0x12fd3c4f0'thing1'](LTR) (Names: '|':UIView:0x12fd3d590 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x12fd39a60 UIButton:0x12fd3c4f0'thing1'.leading == UIView:0x12fd3d590.leadingMargin>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2015-12-10 22:59:01.327 Storyboard[7647:5116727] 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.
(
"<_UILayoutSupportConstraint:0x12fea5ac0 V:[_UILayoutGuide:0x12fd3d960(0)]>",
"<_UILayoutSupportConstraint:0x12fe9e960 V:|-(0)-[_UILayoutGuide:0x12fd3d960] (Names: '|':UIView:0x12fd3d590 )>",
"<NSLayoutConstraint:0x12fd3d800 V:[_UILayoutGuide:0x12fd3d960]-(0)-[UIButton:0x12fd3c4f0'thing1']>",
"<NSIBPrototypingLayoutConstraint:0x12fea5e40 'IB auto generated at build time for view with fixed frame' V:|-(20)-[UIButton:0x12fd3c4f0'thing1'] (Names: '|':UIView:0x12fd3d590 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x12fd3d800 V:[_UILayoutGuide:0x12fd3d960]-(0)-[UIButton:0x12fd3c4f0'thing1']>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
为什么?
【问题讨论】:
-
当您在代码中添加
NSLayoutContraint集时,您是否删除了情节提要中的那些,因此您不会尝试向同一个项目添加第二个集? -
@NikMos 我没有在界面生成器中添加任何约束。
标签: ios autolayout