如何获得自动布局以覆盖UIImageView的固有大小? [英] How can I get autolayout to override a UIImageView's intrinsic size?

查看:77
本文介绍了如何获得自动布局以覆盖UIImageView的固有大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在UISplitViewController中的详细视图的自动版式遇到问题.我的视图层次结构包含一个带有装饰元素的UIImageView,并且图像视图的固有大小似乎正在破坏其余控件的布局.

I'm running into a problem with the autolayout for my detail view in a UISplitViewController. My view hierarchy contains a UIImageView with a decorative element, and the image view's intrinsic size seems to be screwing up the layout of the rest of the controls.

这些是我为图像视图指定的约束:

These are the constraints I have specified for the image view:

H:[UIImageView:0xc83ba90]-(NSSpace(20))-|
H:|-(NSSpace(20))-[UIImageView:0xc83ba90]
UIImageView:0xc83ba90.bottom == UITextField:0xc83d2d0.bottom
V:[UIImageView:0xc83ba90 (3)]>,
H:[UIImageView:0xc83ba90 (532)] Hug:1 CompressionResistance:750
V:[UIImageView:0xc83ba90 (2)] Hug:250 CompressionResistance:750

我想要的行为是调整图像视图的大小以填充其超级视图,如前两个约束所述.我看到的实际行为是图像视图仅占用其固有尺寸约束所描述的水平空间.它似乎也正在改变其所有同级视图的布局,就像超级视图只是将视图布局成与图像视图一样宽的矩形一样.

The behavior I want is for the image view to be resized to fill its superview, as described by the top two constraints. The actual behavior I'm seeing is that the image view only takes up horizontal space described by its intrinsic size constraint. It also seems to be altering the layout of all of its sibling views, as though the superview were only laying out views in a rectangle as wide as the image view.

我认为将图像视图的拥抱优先级指定得越低越好,其他约束将覆盖它以调整图像视图的大小.我在这里做什么错了?

I thought that specifying the hugging priority of the image view as low as possible would let the other constraints override it to resize the image view. What am I doing wrong here?

推荐答案

所以,我终于找到了解决方案.

So, I finally found a solution.

解决方案是将 SuperView的拥抱优先级提高到高(750或更高),并将 UIImageView的抗压缩优先级降低到低(250或更低). 这将使约束覆盖图像的本征大小.

Solution is to increase the Hugging Priority of SuperView to High(750 or more) and decrease the Compression Resistance Priority of UIImageView to Low(250 or less). This will let constraints override the image Intrinsic Size.

Content Hugging Priority - The higher this priority is, the more a view resists growing larger than its intrinsic content size.
Content Compression Resistance Priority - The higher this priority is, the more a view resists shrinking smaller than its intrinsic content size. 

这篇关于如何获得自动布局以覆盖UIImageView的固有大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆