NSLayoutConstraint 和动态宽高
NSLayoutConstraint and dynamic width and height
我有这个代码:
[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)-|"
,但我也遇到了错误。
您要设置myView.translatesAutoresizingMaskIntoConstraints = NO
我有这个代码:
[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)-|"
,但我也遇到了错误。
您要设置myView.translatesAutoresizingMaskIntoConstraints = NO