无法同时满足约束 - 同时添加子视图

时间:2013-10-24 08:45:00

标签: ios autolayout

我正在使用xib中的故事板。

我从故事板加载UIViewController并从xib加载UIView。我正在尝试将xib添加为故事板UIViewController的子视图,并将其设置为底部constratint:

TransactionsPickerViewController *_picker = [[TransactionsPickerViewController alloc] initWithNibName:nil bundle:nil];
[self.view addSubview:picker.view];

NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:picker.view
                                                            attribute:NSLayoutAttributeBottom
                                                            relatedBy:NSLayoutRelationEqual
                                                            toItem:self.view
                                                            attribute:NSLayoutAttributeBottom
                                                            multiplier:1.0f constant:0.0f];
[self.view addConstraint:constraint];

它在调试控制台中导致这种情况:

Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want...

UIView property translatesAutoresizingMaskIntoConstraints) 
(
    "<NSLayoutConstraint:0x1090509e0 UIView:0x109440be0.bottom == UIView:0x109619ba0.bottom>",
    "<NSAutoresizingMaskLayoutConstraint:0x109052400 h=-&- v=-&- UIView:0x109440be0.midY == UIView:0x109619ba0.midY - 140>",
    "<NSAutoresizingMaskLayoutConstraint:0x109052470 h=-&- v=-&- UIView:0x109440be0.height == UIView:0x109619ba0.height - 280>"
)

这些自动调整属性来自哪里,我可以摆脱它们以使其工作吗?实际上,我想在添加后将我的选择器视图粘贴到父视图底部。

我尝试在xib文件上禁用自动布局,但它不会改变任何内容。

1 个答案:

答案 0 :(得分:3)

您的错误可能是因为在将其添加为子视图之前未设置picker.view. translatesAutoresizingMaskIntoConstraints = NO;

但是,在我看来,您应该添加TransactionsPickerViewController作为子视图控制器,而不是仅使用其视图。请参阅以下部分:Implementing a Custom Container View ControllerImplementing a Container View Controller