与Segment一起使用约束时的冲突

时间:2015-01-29 15:37:03

标签: ios constraints

所以我在故事板中添加了段,并在遇到此问题时使用Add Missing约束。

App Screenshot

这个非常复杂(对我而言)错误:

2015-01-29 22:29:16.151 MafiaPhone[45162:1236769] 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) 
(
"<_UILayoutSupportConstraint:0x7f9e397572b0 V:[_UILayoutGuide:0x7f9e39627f00(64)]>",
"<_UILayoutSupportConstraint:0x7f9e3975cbb0 V:|-(0)-[_UILayoutGuide:0x7f9e39627f00]   (Names: '|':UIView:0x7f9e39627e30 )>",
"<_UILayoutSupportConstraint:0x7f9e39748a80 V:[_UILayoutGuide:0x7f9e396286b0(0)]>",
"<_UILayoutSupportConstraint:0x7f9e3972bc70 _UILayoutGuide:0x7f9e396286b0.bottom == UIView:0x7f9e39627e30.bottom>",
"<NSLayoutConstraint:0x7f9e39732f20 V:[_UILayoutGuide:0x7f9e39627f00]-(106)-[UITextField:0x7f9e39628e00]>",
"<NSLayoutConstraint:0x7f9e3974bb80 V:[UILabel:0x7f9e397528a0'Role Name']-(29)-[UILabel:0x7f9e3970c3e0'Side']>",
"<NSLayoutConstraint:0x7f9e3971d360 UILabel:0x7f9e3970c3e0'Side'.lastBaseline == UISegmentedControl:0x7f9e39749690.firstBaseline>",
"<NSLayoutConstraint:0x7f9e39747ac0 UILabel:0x7f9e397528a0'Role Name'.lastBaseline == UITextField:0x7f9e39628e00.firstBaseline>",
"<NSLayoutConstraint:0x7f9e39747b10 V:[UISegmentedControl:0x7f9e39749690]-(37)-[UIButton:0x7f9e39737e20'Add']>",
"<NSLayoutConstraint:0x7f9e39754070 UIButton:0x7f9e39737e20'Add'.centerY == UIView:0x7f9e39627e30.centerY>",
"<NSLayoutConstraint:0x7f9e397540c0 V:[UIButton:0x7f9e39737e20'Add']-(241)-[_UILayoutGuide:0x7f9e396286b0]>",
"<NSLayoutConstraint:0x7f9e39754160 UISegmentedControl:0x7f9e39749690.lastBaseline == UILabel:0x7f9e3970c3e0'Side'.firstBaseline>",
"<NSLayoutConstraint:0x7f9e39754200 UISegmentedControl:0x7f9e39749690.lastBaseline == UILabel:0x7f9e3970c3e0'Side'.lastBaseline>",
"<NSLayoutConstraint:0x7f9e39754250 V:[UISegmentedControl:0x7f9e39749690(28)]>",
"<NSAutoresizingMaskLayoutConstraint:0x7f9e39521a20 h=--& v=--& UISegment:0x7f9e3972eef0.midY == + 14.5>",
"<NSLayoutConstraint:0x7f9e3951a7a0 UISegmentLabel:0x7f9e39732a30'Second'.centerY == UISegment:0x7f9e3972eef0.centerY>",
"<NSLayoutConstraint:0x7f9e3954b6d0 V:|-(6)-[_UIBaselineLayoutStrut:0x7f9e39760330]   (Names: '|':UITextField:0x7f9e39628e00 )>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7f9e3951a7a0 UISegmentLabel:0x7f9e39732a30'Second'.centerY == UISegment:0x7f9e3972eef0.centerY>

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.

细分是唯一有错误显示位置的部分。这是约束选项。

Constrain Option

我的问题是: 1.错误是什么意思? 2.如何解决这个问题? 3.正在使用&#34;添加缺失约束&#34;是正确的事情(到目前为止,我做的唯一一件事就是让运行视图看起来与故事板视图完全一样)?为什么呢?

感谢阅读整篇长篇文章。希望你能帮助我解决这个令人沮丧的错误!

1 个答案:

答案 0 :(得分:1)

看起来您的系统有太多限制。 &#34;添加&#34;按钮具有centerY约束,以及将其固定到其上方视图的约束,以及底部布局指南。很难知道你想要哪些约束。我会删除&#34; Add&#34;之间的那个。按钮和底部布局指南,以及文本字段和导航栏之间的一个。

通过使用&#34;添加缺少的约束&#34;,你真的不应该在一组复杂的视图上设置约束。明确添加您需要的那些。如果您不知道如何操作,请观看2012 WWDC中有关自动布局的视频。