我想根据视图高度以编程方式设置我的约束。例如,我想从视图设置我的约束顶部等于(self.view.height)* 0.05。然而,据我了解它是不可能的,如果你尝试这样做,应用程序将引发异常。处理iPad视图的自动布局
我用砖石(库帮助编程易于设置的限制),而且我发现答案:
you cannot relate size attributes (height, width) to position attributes (left, top etc)
If you wanted 20% margin on both top and bottom you could create a constraint which is
make.height.equalTo(superview.mas_height).multipliedBy(60/100.0);
make.center.equalTo(superview.mas_center);
任何方式来实现这一点?谢谢。
编辑:
例如,该代码将引发异常:从典型的以编程方式添加约束语法
[imageNewsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(self.view.mas_height)multiplyBy(0.2);
它的不同,但我希望戒烟理解明显。 That will raise an exception: invalid pairing of layout attributes.
@matt my bad。我更新了问题主体。 –
@matt您是否会善意地删除downvote,因为我更新了问题主体以符合您的标准。 –