iOS自动布局:在ViewDidLayoutSubView中设置约束?

iOS自动布局:在ViewDidLayoutSubView中设置约束?,ios,objective-c,iphone,autolayout,constraints,Ios,Objective C,Iphone,Autolayout,Constraints,我有一个带有xib的视图控制器。xib包含所有没有约束的子视图,我需要手动添加这些约束。当我在viewDidLoad中编写代码时,一切都是正确的。但是我需要获取一个大小参数,该参数仅在viewdilayoutsubviews中可用。当我试图在viewdilayoutsubviews中调用我的代码时,我得到以下错误: Unable to simultaneously satisfy constraints. Probably at least one of the constraints

我有一个带有xib的
视图控制器
。xib包含所有没有约束的子视图,我需要手动添加这些约束。当我在
viewDidLoad
中编写代码时,一切都是正确的。但是我需要获取一个大小参数,该参数仅在
viewdilayoutsubviews
中可用。当我试图在
viewdilayoutsubviews
中调用我的代码时,我得到以下错误:

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:0x79edebb0 V:|-(50)-[UILabel:0x79f11bf0'You haven't imported any ...']   (Names: '|':UIView:0x79f11940 )>",
    "<NSLayoutConstraint:0x79e4b190 V:|-(49)-[UILabel:0x79f11bf0'You haven't imported any ...']   (Names: '|':UIView:0x79f11940 )>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x79edebb0 V:|-(50)-[UILabel:0x79f11bf0'You haven't imported any ...']   (Names: '|':UIView:0x79f11940 )>

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.
无法同时满足约束。
可能下面列表中至少有一个约束是您不想要的。
试试这个:
(1) 看看每一个约束,试着找出你不期望的;
(2) 找到添加了不需要的约束的代码,然后修复它。
(
""
)
将尝试通过打破约束进行恢复

它表示UILabel中的1个具有破坏布局的约束。 2个选项

  • 清除所有标签的约束,并通过try n error设置每个标签的约束
  • 将id设置为uilabel的所有约束,然后u将在中看到约束的id
  • 警告或错误输出


    基本上,这是由于您添加了一个不需要的约束。

    您添加到
    viewdlayoutsubviews
    中的代码对于查看
    viewdlayoutsubviews
    中的添加约束非常有用,这有点代码味道。也许有更好的方法可以达到同样的效果。