[英]How can I get autolayout to override a UIImageView's intrinsic size?
I'm running into a problem with the autolayout for my detail view in a UISplitViewController
.我在 UISplitViewController 中的详细信息视图的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.我的视图层次结构包含一个带有装饰元素的UIImageView
,图像视图的内在大小似乎搞砸了其余控件的布局。
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.所以,我终于找到了解决办法。
Solution is to increase the Hugging Priority of the superview
to .defaultHigh
and decrease the Compression Resistance Priority of the UIImageView
to .defaultLow
.解决方案是增加的抱死优先superview
向.defaultHigh
和降低抗压性能优先UIImageView
到.defaultLow
。 This will let constraints override the image's 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.内容压缩抵抗优先级 - 此优先级越高,视图越能抵抗缩小小于其固有内容大小。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.