如果我使用AutoLayout定义视图的NSLayoutAttributeLeft和NSLayoutAttributeRight,我可以访问其NSLayoutAttributeWidth吗?

时间:2013-07-19 18:42:50

标签: ios autolayout

例如,假设我有视图a,b和c,我这样做:

[a setTranslatesAutoresizingMaskIntoConstraints:NO];
[b setTranslatesAutoresizingMaskIntoConstraints:NO];
[c setTranslatesAutoresizingMaskIntoConstraints:NO];

[a addSubview:b];
[a addSubview:c];

[a addConstraint:
 [NSLayoutConstraint constraintWithItem:b
                              attribute:NSLayoutAttributeLeft
                              relatedBy:NSLayoutRelationEqual
                                 toItem:a
                              attribute:NSLayoutAttributeLeft
                             multiplier:1.0
                               constant:0]];
[a addConstraint:
 [NSLayoutConstraint constraintWithItem:b
                              attribute:NSLayoutAttributeRight
                              relatedBy:NSLayoutRelationEqual
                                 toItem:a
                              attribute:NSLayoutAttributeRight
                             multiplier:1.0
                               constant:0]];
那么,我应该能够做到:

[a addConstraint:
 [NSLayoutConstraint constraintWithItem:c
                              attribute:NSLayoutAttributeWidth
                              relatedBy:NSLayoutRelationEqual
                                 toItem:a
                              attribute:NSLayoutAttributeWidth
                             multiplier:1.0
                               constant:0]];

如果我改为将最后一个命令改为:

[a addConstraint:
 [NSLayoutConstraint constraintWithItem:c
                              attribute:NSLayoutAttributeWidth
                              relatedBy:NSLayoutRelationEqual
                                 toItem:a
                              attribute:NSLayoutAttributeRight
                             multiplier:1.0
                               constant:0]];

...然后一切正常。是什么赋予了?

0 个答案:

没有答案