Ios 将砌体x/y约束设置为视图宽度/高度的百分比
我正在尝试将视图顶部约束(y值)设置为superview高度的百分比(乘数)。我需要使用引用而不是值约束来解释设备旋转 与我在非自动布局中尝试的内容类似,如下所示:Ios 将砌体x/y约束设置为视图宽度/高度的百分比,ios,objective-c,swift,autolayout,masonry-ios-osx,Ios,Objective C,Swift,Autolayout,Masonry Ios Osx,我正在尝试将视图顶部约束(y值)设置为superview高度的百分比(乘数)。我需要使用引用而不是值约束来解释设备旋转 与我在非自动布局中尝试的内容类似,如下所示: [self.labelView setFrame:CGRectMake(0, self.frame.size.height * 0.8, self.frame.size.width, 20)]; [self.labelView mas_makeConstraints:^(MASConstraintMaker *make) {
[self.labelView setFrame:CGRectMake(0, self.frame.size.height * 0.8, self.frame.size.width, 20)];
[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);
}];
我试图实现的是将视图的顶部约束设置为superviews高度的80%,如下所示:
[self.labelView setFrame:CGRectMake(0, self.frame.size.height * 0.8, self.frame.size.width, 20)];
[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\u height
使用contentView.mas\u bottom
,尝试设置labelView.top
或labelView.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)
}
我不熟悉砌体,但我使用过约束。Try:
make.top.equalTo(self.contentView.bottom).乘以(0.8)代码>obj-c代码正是我想要的。非常感谢。