iOS 8声明UIView的addConstraints已弃用,应使用NSLayoutConstraints + activateConstraints。所以我做了一个快速测试,但事情并没有适用于新方法。
来自viewdidload或viewdidappear:
作品(标签调整大小):
NSDictionary *views = NSDictionaryOfVariableBindings(_labelLeft);
NSArray *constraints = [NSLayoutConstraint
constraintsWithVisualFormat:@"V:[_labelLeft(100)]"
options:0
metrics:nil
views:views];
NSArray *constraint = [NSLayoutConstraint
constraintsWithVisualFormat:@"H:[_labelLeft(100)]"
options:0
metrics:nil
views:views];
[self.view addConstraints:constraints];
[self.view addConstraints:constraint];
不起作用
NSDictionary *views = NSDictionaryOfVariableBindings(_labelLeft);
NSArray *constraints = [NSLayoutConstraint
constraintsWithVisualFormat:@"V:[_labelLeft(100)]"
options:0
metrics:nil
views:views];
NSArray *constraint = [NSLayoutConstraint
constraintsWithVisualFormat:@"H:[_labelLeft(100)]"
options:0
metrics:nil
views:views];
[NSLayoutConstraint activateConstraints:constraint];
[NSLayoutConstraint activateConstraints:constraints];
任何人都知道我做错了什么?