NSLayoutConstraint和动态宽度和高度

时间:2015-04-10 20:58:14

标签: ios nslayoutconstraint

我有这段代码:

[parent.view addConstraints:[NSLayoutConstraint
    constraintsWithVisualFormat:@"H:|-(0)-[myView]-(0)-|"
                        options:NSLayoutFormatDirectionLeadingToTrailing
                        metrics:nil
                          views:@{ @"myView":myView }]];

我可能理解错了,我不知道。我希望myView遍布parent.view区域。但我刚收到一个错误:

Unable to simultaneously satisfy constraints.
translatesAutoresizingMaskIntoConstraints) 
(
    "<NSLayoutConstraint:0x14d645d0 H:|-(0)-[UIView:0x14d32ce0]   (Names: '|':UILayoutContainerView:0x14dbd6a0 )>",
    "<NSLayoutConstraint:0x14d64600 H:[UIView:0x14d32ce0]-(0)-|   (Names: '|':UILayoutContainerView:0x14dbd6a0 )>",
    "<NSAutoresizingMaskLayoutConstraint:0x16184340 h=-&- v=-&-UIView:0x14d32ce0.midX == UILayoutContainerView:0x14dbd6a0.midX + 140>"
)

我试过了@"[myView]-(0)-|",但我也遇到了错误。

1 个答案:

答案 0 :(得分:2)

您想要设置myView.translatesAutoresizingMaskIntoConstraints = NO