简体   繁体   English

使用自动布局将多个具有不同高度的视图居中

[英]Center multiple views with varying height using autolayout

This answer: https://stackoverflow.com/a/25898949/1364053 is suitable for my problem to some extent. 这个答案: https : //stackoverflow.com/a/25898949/1364053在某种程度上适合我的问题。 What I need is there are three views in my container view. 我需要的是容器视图中的三个视图。

The middle one is a scroll view. 中间一个是滚动视图。 If I pin height and width of all three views and use the ratio method as described in the above link, all works fine. 如果我固定了所有三个视图的高度和宽度,并使用上述链接中所述的比率方法,则一切正常。

But I need the middle scrollview to grow to some extent, let's say the current height of the scroll view is 30, If the device height is increased it should grow to a max of 40 but not more than that (<= constraint). 但是我需要中间的滚动视图在某种程度上增长,比方说当前滚动视图的高度是30。如果设备的高度增加,它应该增长到最大40,但不能超过这个最大值(<=约束)。

Ok..So I tried giving two constraints to the middle view. 好的,所以我尝试给中间视图施加两个约束。 The <= constraint has higher priorty (750) than the = constraint (250).. but when the screen size is increased.. the height stays the same. <=约束具有比=约束(250)高的优先级(750)。但是,当屏幕尺寸增加时,高度保持不变。 在此处输入图片说明

在此处输入图片说明

Sample.xib The uploaded xib might help you. Sample.xib上传的xib可能会帮助您。

约束截图

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

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