对 Segment 使用约束时发生冲突

Conflict when using constraint with Segment

因此,当我 运行 解决此问题时,我将片段添加到情节提要中并使用添加缺失约束。

这个(对我来说)非常复杂的错误:

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.

Segment 是唯一出现位置错误的部分。这里是约束选项。

我的问题是: 1.错误是什么意思? 2.如何解决这个问题? 3. 使用 "Add missing constraints" 是正确的做法吗(到目前为止,这是我使 运行 视图看起来与故事板视图完全一样的唯一方法)?为什么?

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

您的系统似乎有太多限制。 "Add" 按钮有一个 centerY 约束,以及将其固定到其上方视图的约束,以及底部布局指南。很难知道您想要哪些约束。我会删除 "Add" 按钮和底部布局指南之间的那个,还有文本字段和导航栏之间的那个。

您真的不应该使用 "add missing constraints" 对一组复杂的视图设置约束。添加您明确需要的那些。如果您不知道该怎么做,请观看 2012 WWDC 上关于自动布局的视频。