Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/114.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 将砌体x/y约束设置为视图宽度/高度的百分比_Ios_Objective C_Swift_Autolayout_Masonry Ios Osx - Fatal编程技术网

Ios 将砌体x/y约束设置为视图宽度/高度的百分比

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) {

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

与我在非自动布局中尝试的内容类似,如下所示:

[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代码正是我想要的。非常感谢。