Ios 当我运行应用程序时,布局被忽略

Ios 当我运行应用程序时,布局被忽略,ios,objective-c,autolayout,nslayoutconstraint,Ios,Objective C,Autolayout,Nslayoutconstraint,我尝试以编程方式向UICollectionView和UILabel添加约束。我是这样做的: [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[_labelToChange(30)]-0-[_datesCollectionView]-0-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_labelToChange, _

我尝试以编程方式向
UICollectionView
UILabel
添加约束。我是这样做的:

[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[_labelToChange(30)]-0-[_datesCollectionView]-0-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_labelToChange, _datesCollectionView)]];
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[_labelToChange]-0-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_labelToChange)]];
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[_datesCollectionView]-0-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_datesCollectionView)]];
当我运行应用程序时,
约束被忽略,我得到以下错误:

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:0x7f96c9daae70 H:|-(0)-[UICollectionView:0x7f96ca15a800]   (Names: '|':DIDatepicker:0x7f96c9d7f950 )>",
    "<NSAutoresizingMaskLayoutConstraint:0x7f96c9db6b00 h=--& v=--& UICollectionView:0x7f96ca15a800.midX == + 300>",
    "<NSAutoresizingMaskLayoutConstraint:0x7f96c9db6b50 h=--& v=--& H:[UICollectionView:0x7f96ca15a800(540)]>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7f96c9daae70 H:|-(0)-[UICollectionView:0x7f96ca15a800]   (Names: '|':DIDatepicker:0x7f96c9d7f950 )>

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-06-04 13:58:14.692 myApp[581:8508] 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:0x7f96c9daaad0 H:|-(0)-[UILabel:0x7f96c9da8290]   (Names: '|':DIDatepicker:0x7f96c9d7f950 )>",
    "<NSLayoutConstraint:0x7f96c9daab20 H:[UILabel:0x7f96c9da8290]-(0)-|   (Names: '|':DIDatepicker:0x7f96c9d7f950 )>",
    "<NSLayoutConstraint:0x7f96c9daaef0 H:[UICollectionView:0x7f96ca15a800]-(0)-|   (Names: '|':DIDatepicker:0x7f96c9d7f950 )>",
    "<NSAutoresizingMaskLayoutConstraint:0x7f96c9db6b00 h=--& v=--& UICollectionView:0x7f96ca15a800.midX == + 300>",
    "<NSAutoresizingMaskLayoutConstraint:0x7f96c9db6b50 h=--& v=--& H:[UICollectionView:0x7f96ca15a800(540)]>",
    "<NSAutoresizingMaskLayoutConstraint:0x7f96c9db6e40 h=--& v=--& UILabel:0x7f96c9da8290.midX == + 300>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7f96c9daab20 H:[UILabel:0x7f96c9da8290]-(0)-|   (Names: '|':DIDatepicker:0x7f96c9d7f950 )>

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-06-04 13:58:14.696 myApp[581:8508] 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:0x7f96c9daaad0 H:|-(0)-[UILabel:0x7f96c9da8290]   (Names: '|':DIDatepicker:0x7f96c9d7f950 )>",
    "<NSAutoresizingMaskLayoutConstraint:0x7f96c9db6e40 h=--& v=--& UILabel:0x7f96c9da8290.midX == + 300>",
    "<NSAutoresizingMaskLayoutConstraint:0x7f96c9db8960 h=--& v=--& H:[UILabel:0x7f96c9da8290(540)]>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7f96c9daaad0 H:|-(0)-[UILabel:0x7f96c9da8290]   (Names: '|':DIDatepicker:0x7f96c9d7f950 )>

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-06-04 13:58:14.699 myApp[581:8508] 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:0x7f96c9d80160 H:|-(0)-[DIDatepicker:0x7f96c9d7f950]   (Names: '|':UITableViewCellContentView:0x7f96c9d7f330 )>",
    "<NSLayoutConstraint:0x7f96c9d80200 H:[DIDatepicker:0x7f96c9d7f950]-(0)-|   (Names: '|':UITableViewCellContentView:0x7f96c9d7f330 )>",
    "<NSLayoutConstraint:0x7f96c9daaef0 H:[UICollectionView:0x7f96ca15a800]-(0)-|   (Names: '|':DIDatepicker:0x7f96c9d7f950 )>",
    "<NSAutoresizingMaskLayoutConstraint:0x7f96c9db6b00 h=--& v=--& UICollectionView:0x7f96ca15a800.midX == + 300>",
    "<NSAutoresizingMaskLayoutConstraint:0x7f96c9db6b50 h=--& v=--& H:[UICollectionView:0x7f96ca15a800(540)]>",
    "<NSLayoutConstraint:0x7f96c9db7dd0 'fittingSizeHTarget' H:[UITableViewCellContentView:0x7f96c9d7f330(375)]>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7f96c9daaef0 H:[UICollectionView:0x7f96ca15a800]-(0)-|   (Names: '|':DIDatepicker:0x7f96c9d7f950 )>
无法同时满足约束。
可能下面列表中至少有一个约束是您不想要的。试着这样做:(1)看看每个约束,试着找出你不期望的约束;(2) 找到添加了不需要的约束的代码,然后修复它。(注意:如果您看到不理解的NSAutoresizingMaskLayoutConstraints,请参阅UIView属性TranslatesAutoResizingMaskToConstraints的文档)
(
"",
"",
""
)
将尝试通过打破约束进行恢复
在UIViewAlertForUnsatifiableConstraints处创建一个符号断点,以便在调试器中捕获该断点。
中列出的UIView上UIConstraintBasedLayoutDebugging类别中的方法也可能会有所帮助。
2015-06-04 13:58:14.692 myApp[581:8508]无法同时满足约束条件。
可能下面列表中至少有一个约束是您不想要的。试着这样做:(1)看看每个约束,试着找出你不期望的约束;(2) 找到添加了不需要的约束的代码,然后修复它。(注意:如果您看到不理解的NSAutoresizingMaskLayoutConstraints,请参阅UIView属性TranslatesAutoResizingMaskToConstraints的文档)
(
"",
"",
"",
"",
"",
""
)
将尝试通过打破约束进行恢复
在UIViewAlertForUnsatifiableConstraints处创建一个符号断点,以便在调试器中捕获该断点。
中列出的UIView上UIConstraintBasedLayoutDebugging类别中的方法也可能会有所帮助。
2015-06-04 13:58:14.696 myApp[581:8508]无法同时满足约束条件。
可能下面列表中至少有一个约束是您不想要的。试着这样做:(1)看看每个约束,试着找出你不期望的约束;(2) 找到添加了不需要的约束的代码,然后修复它。(注意:如果您看到不理解的NSAutoresizingMaskLayoutConstraints,请参阅UIView属性TranslatesAutoResizingMaskToConstraints的文档)
(
"",
"",
""
)
将尝试通过打破约束进行恢复
在UIViewAlertForUnsatifiableConstraints处创建一个符号断点,以便在调试器中捕获该断点。
中列出的UIView上UIConstraintBasedLayoutDebugging类别中的方法也可能会有所帮助。
2015-06-04 13:58:14.699 myApp[581:8508]无法同时满足约束条件。
可能下面列表中至少有一个约束是您不想要的。试着这样做:(1)看看每个约束,试着找出你不期望的约束;(2) 找到添加了不需要的约束的代码,然后修复它。(注意:如果您看到不理解的NSAutoresizingMaskLayoutConstraints,请参阅UIView属性TranslatesAutoResizingMaskToConstraints的文档)
(
"",
"",
"",
"",
"",
""
)
将尝试通过打破约束进行恢复

您是否尝试过设置
self.translatesAutoResizengMaskintoConstraints=否?刚试过。相同的Resluts您应该为_labelToChange和datesCollectionView将translatesAutoresizingMaskIntoConstraints设置为NO,而不是为self。@rdelmar谢谢!!刚刚试过,现在它在没有警告的情况下工作了。但是现在,当我执行self.datesCollectionView选择ItemAtIndexPath:animated:scrollPosition:UICollectionViewScrollPositionCenter水平时,它不会滚动?这是另一个问题。如果你想不出来,你应该提出一个新问题。