Ios 为什么不';这些约束不起作用吗?

Ios 为什么不';这些约束不起作用吗?,ios,cocoa-touch,uiview,constraints,autolayout,Ios,Cocoa Touch,Uiview,Constraints,Autolayout,我正在以编程方式对UIView中的三个视图设置以下约束: UIView *view1 = ((UIViewController *)[self.viewControllers objectAtIndex:0]).view; UIView *view2 = ((UIViewController *)[self.viewControllers objectAtIndex:1]).view; UIView *view3 = ((UIViewController *)[self.viewControll

我正在以编程方式对UIView中的三个视图设置以下约束:

UIView *view1 = ((UIViewController *)[self.viewControllers objectAtIndex:0]).view;
UIView *view2 = ((UIViewController *)[self.viewControllers objectAtIndex:1]).view;
UIView *view3 = ((UIViewController *)[self.viewControllers objectAtIndex:2]).view;

NSDictionary *viewsDictionary = NSDictionaryOfVariableBindings(view1, view2, view3);
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[view1(==320)]-0-[view2(==320)]-0-[view3(==320)]|" options:0 metrics:0 views:viewsDictionary]];
我的意图是,每个视图都是320px宽的,彼此齐平,没有间隙,并且一个视图对着视图的左边缘

但是,在编译时,这些视图被放置在彼此的顶部,我在控制台中看到以下内容:

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:0x211811c0 H:|-(0)-[UIView:0xc683790]   (Names: '|':UIView:0xc683320 )>",
    "<NSAutoresizingMaskLayoutConstraint:0x21179820 h=-&- v=-&- UIView:0xc683790.midX == UIView:0xc683320.midX - 340>",
    "<NSLayoutConstraint:0x211793d0 H:[UIView:0xc6a50c0]-(0)-|   (Names: '|':UIView:0xc683320 )>",
    "<NSLayoutConstraint:0x21179390 H:[UIView:0xc6a50c0(320)]>",
    "<NSLayoutConstraint:0x21179350 H:[UIView:0xc6a05f0]-(0)-[UIView:0xc6a50c0]>",
    "<NSLayoutConstraint:0x211563d0 H:[UIView:0xc6a05f0(320)]>",
    "<NSLayoutConstraint:0x21156390 H:[UIView:0xc683790]-(0)-[UIView:0xc6a05f0]>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x21179350 H:[UIView:0xc6a05f0]-(0)-[UIView:0xc6a50c0]>
无法同时满足约束。
可能下面列表中至少有一个约束是您不想要的。试着这样做:(1)看看每个约束,试着找出你不期望的约束;(2) 找到添加了不需要的约束的代码,然后修复它。(注意:如果您看到不理解的NSAutoresizingMaskLayoutConstraints,请参阅UIView属性TranslatesAutoResizingMaskToConstraints的文档)
(
"",
"",
"",
"",
"",
"",
""
)
将尝试通过打破约束进行恢复
尝试设置

[view setTranslatesAutoresizingMaskIntoConstraints:NO];
对于你所有的观点,这通常足以解决这类问题