简体   繁体   中英

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)

I defined leading space, trailing space, bottom space which its constant = 0 with superview.bottom.

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

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.

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.

Thanks a lot for your time.

Set the view Equal Heights with its superview. Then change the multiplier of the Equal Heights constraint to 1:3

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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