视图和Superview自动布局的比例高度 [英] proportional height of view and superview autolayout
问题描述
我有一个小小的观点,我希望他占据超级视图的1/3高度(与安全区域相同的大小)
I have a small view that I want him occupy 1/3 height of superview(same size with safe area)
我用superview.bottom定义了常数为0的前导空间,尾随空间,底部空间.
I defined leading space, trailing space, bottom space which its constant = 0 with superview.bottom.
并且我想将Superview高度的高度设为1/3,以使其在所有iphone尺寸中都具有相同的外观.我定义了宽高比,并将其第一项更改为superview.height,将第二项更改为thisview.height.我当然定义了3:1乘数
AND I want to make the height 1/3 of superview height to make it same look in all iphone sizes. I defined aspect ratio and changed its first item as superview.height and second item as thisview.height. of course I have defined 3:1 multiplier
但是它不起作用,会出现以下错误
But it doesnt work it gives following error
由于未捕获的异常"NSGenericException"而终止应用程序, 原因:无法在视图上安装约束.是否有约束 从视图的子树外部引用某些内容?那是 非法的.
Terminating app due to uncaught exception 'NSGenericException', reason: 'Unable to install constraint on view. Does the constraint reference something from outside the subtree of the view? That's illegal.
来吧!为什么不起作用?与其他所有内容相比,这并不复杂. 另外,我该如何在界面上完成此操作. (不在代码中)我想在xcode上与预览"标签中的所有其他屏幕尺寸一起看到它.
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.
非常感谢您的时间.
推荐答案
设置视图Equal Heights
及其超级视图.然后将Equal Heights
约束的乘数更改为1:3
Set the view Equal Heights
with its superview. Then change the multiplier of the Equal Heights
constraint to 1:3
这篇关于视图和Superview自动布局的比例高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!