gpt4 book ai didi

ios - 将砌体 x/y 约束设置为 View 宽度/高度的百分比

转载 作者:行者123 更新时间:2023-11-28 05:42:27 25 4
gpt4 key购买 nike

我试图将我的 View 顶部约束(y 值)设置为父 View 高度的百分比(乘数)。我需要使用引用而不是值约束来解释设备旋转。

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

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

我想要实现的是将 View 的 TOP 约束设置为父 View 高度的 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);
}];

但是,这种方法行不通。 Masonry 库可以做到这一点吗?

最佳答案

使用 contentView.mas_bottom 代替 contentView.mas_height,尝试设置 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);
}];

Swift 等价物

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com