简体   繁体   English

IOs自动布局最高位置

[英]IOs Autolayout top position

I've a problem with my layout and don't find suggestions to solve. 我的版式有问题,找不到解决的建议。 My scenario is: 我的情况是:

I've 2 views (a UIImageView and a UILabel) side by side and with dynamic height and I need to put another view bellow the tallest of the two views. 我有2个视图(一个UIImageView和一个UILabel)并排并且具有动态高度,我需要在另一个视图中放两个视图中最高的一个。

This image illustrates my problem, but I'm creating that views programmatically. 此图像说明了我的问题,但是我正在以编程方式创建该视图。

http://i.stack.imgur.com/fRSib.png http://i.stack.imgur.com/fRSib.png

These are my constraints: 这些是我的约束:

H:|-8-[UIImageView]-8-[Label1]-8|
V:|-8-[UIImageView]
V:|-8-[Label1]
H:|-8-[Label2]-8|
V:[UIImageView]-(>=8)-[Label2]
V:[Label1]-(>=8)-[Label2]

I know that my layout is ambiguous, but I can't to solve this. 我知道我的布局不明确,但是我无法解决。

Thanks for help 感谢帮助

You need to add constraints with priorities and you need an additional constraint. 您需要添加具有优先级的约束,并且还需要其他约束。 Your current spec is ambiguous because there are multiple potential solutions. 您当前的规范含糊不清,因为有多种潜在的解决方案。

The 2 constraints to position the Label2 based on the heights need to be high priority (the default). 基于高度放置Label2的2个约束必须具有较高的优先级(默认)。 You also need another constraint of a low priority which tells the layout system what you prefer - Ie That the y position should be the maximum, because the low priority constraint specifies that the label should be pinned to the bottom of the container / a static value larger then the possible heights of the other views. 您还需要另一个低优先级约束,该约束告诉布局系统您喜欢的布局-即y位置应为最大值,因为低优先级约束指定标签应固定在容器底部/静态值大于其他视图的可能高度。

The visual constraint language is a convenience but it doesn't allow you to specify everything. 视觉约束语言是一种便利,但是它不允许您指定所有内容。

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

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