1

我有一个自动布局约束,它在选项卡栏上方附加一个视图。这个细节并不重要,它工作正常。

NSDictionary *views = @{@"view":self.collectionSelectionContainer, @"bottomLayoutGuide":self.bottomLayoutGuide};
NSDictionary *metrics = @{@"offset":@(tabBarHeight)};
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[view]-offset-[bottomLayoutGuide]" options:0 metrics:metrics views:views]];

但是,我想使用另一种方法创建此约束:

[NSLayoutConstraint constraintWithItem:attribute:relatedBy:toItem:attribute:multiplier:constant:]

我尝试了各种方法都没有成功。谁能告诉我怎么做?

谢谢

4

1 回答 1

2

我想我可以只检查从 ConstraintsWithVisualFormat 返回的 NSLayoutConstraint 数组!这实际上是一种很好的解决方法,然后从那里构建方法:

答案是这样的:

self.collectionSelectionBottomConstraint = [NSLayoutConstraint constraintWithItem:self.bottomLayoutGuide attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.collectionSelectionContainer attribute:NSLayoutAttributeBottom multiplier:1 constant:tabBarHeight];
[self.view addConstraint:self.collectionSelectionBottomConstraint];

我认为我之前不成功的原因是我通过了 0 作为乘数。

于 2013-09-03T15:24:29.297 回答