我试图将视图的顶部约束(y值)设置为 super 视图高度的百分比(乘数)。我需要使用参考而不是值约束来说明设备旋转。

我在非自动布局中尝试的等效内容如下:

[self.labelView setFrame:CGRectMake(0, self.frame.size.height * 0.8, self.frame.size.width, 20)];

我想要实现的是将视图的TOP约束设置为 super 视图高度的80%,如下所示:
[self.labelView mas_makeConstraints:^(MASConstraintMaker *make) {
    make.top.equalTo(self.contentView.mas_height).multipliedBy(0.8);
    make.left.and.right.equalTo(self.contentView);
    make.height.equalTo(20);
}];

但是,这种方法不起作用。石工图书馆有可能吗?

最佳答案

而不是contentView.mas_height使用contentView.mas_bottom,尝试设置labelView.toplabelView.bottom约束,我认为两者都应产生相同的结果:

[labelView mas_makeConstraints:^(MASConstraintMaker *make) {
    make.bottom.equalTo(self.contentView.mas_bottom).multipliedBy(0.8);
    make.left.and.right.equalTo(self.contentView);
    make.height.equalTo(@20);
}];

斯威夫特等效
labelView.mas_makeConstraints { (make:MASConstraintMaker!) in
    make.bottom.equalTo()(self.contentView.mas_bottom)!.multipliedBy()(0.8)
    make.left.and().right().mas_equalTo()(self.contentView)
    make.height.mas_equalTo()(20.0)
}

关于ios - 将砌体x/y约束设置为 View 宽度/高度的百分比,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56138348/

10-14 21:48
查看更多