1

我在xib中使用故事板。

UIViewController从情节UIView提要加载并从xib加载。我正在尝试将 xib 作为子视图添加到情节提要UIViewController并设置它的底部约束,如下所示:

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>"
)

这些自动调整大小的属性来自哪里,我可以摆脱它们以使其工作吗?Baically 我希望我的选择器视图在添加后坚持到父视图底部。

我试图在 xib 文件上禁用自动布局,但它没有改变任何东西。

4

1 回答 1

3

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

但是,在我看来,您应该添加 aTransactionsPickerViewController作为子视图控制器,而不仅仅是使用它的视图。请参阅以下部分:实现自定义容器视图控制器实现容器视图控制器

于 2013-10-24T10:38:28.207 回答