简体   繁体   English

视图和超级视图自动布局的比例高度

[英]proportional height of view and superview autolayout

I have a small view that I want him occupy 1/3 height of superview(same size with safe area) 我有一个小小的观点,我想让他占据1/3的超级视图高度(与安全区域相同的大小)

I defined leading space, trailing space, bottom space which its constant = 0 with superview.bottom. 我用superview.bottom定义了其常量= 0的前导空间,尾随空间,底部空间。

AND I want to make the height 1/3 of superview height to make it same look in all iphone sizes. 而且我想将Superview高度的高度设为1/3,以使其在所有iPhone尺寸中都具有相同的外观。 I defined aspect ratio and changed its first item as superview.height and second item as thisview.height. 我定义了宽高比,并将其第一项更改为superview.height,将第二项更改为thisview.height。 of course I have defined 3:1 multiplier 我当然定义了3:1乘数 在此处输入图片说明 在此处输入图片说明

But it doesnt work it gives following error 但它不起作用,它给出以下错误

Terminating app due to uncaught exception 'NSGenericException', reason: 'Unable to install constraint on view. 由于未捕获的异常“ NSGenericException”而终止应用程序,原因:“无法在视图上安装约束。 Does the constraint reference something from outside the subtree of the view? 约束是否引用了视图子树之外的内容? That's illegal. 那是非法的。

Come on!! 来吧!! why doesnt it work? 为什么不起作用? this is not that complex compared to all other stuff. 与其他所有内容相比,这并不复杂。 Also how can I complish this on interface. 另外,我该如何在界面上完成此操作。 (not in code) I would like to see it on xcode with all other screensizes in preview tab. (不在代码中)我想在xcode上与“预览”标签中的所有其他屏幕尺寸一起看到它。

Thanks a lot for your time. 非常感谢您的宝贵时间。

Set the view Equal Heights with its superview. 设置视图Equal Heights及其视图。 Then change the multiplier of the Equal Heights constraint to 1:3 然后将Equal Heights约束的乘数更改为1:3

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM