简体   繁体   English

如何让自动布局覆盖 UIImageView 的固有大小?

[英]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.

相关问题 如何在应用自动布局后获取UIImageView大小? - How to get UIImageView size after autolayout is applied? UITableviewCell中UIImageView的固有内容大小 - UIImageView's intrinsic content size in UITableviewCell 如何在UITableViewCell中获取UIImageView大小(任何对象,如UIButton,UILabel)。 我用了自动排版 - How to get UIImageView Size (any Object Like UIButton, UILabel) in UITableViewCell. I used Autolayout 自动布局,灵活的容器-容器的固有内容大小 - Autolayout, flexible container - container's intrinsic content size 如何让superview适合自动布局的最大内在大小子视图 - How to have superview fit to largest intrinsic size subview with autolayout 如何使用AutoLayout使UIImage的高度与UILabel的固有高度相同? - How can I make my UIImage the same height as the intrinsic height of my UILabel using AutoLayout? 如何在UILabel的内在内容大小中添加填充? - How can I add padding to the intrinsic content size of UILabel? 如何获取UIImageView的图形上下文? - How can I get an UIImageView's graphic context? 如何模糊UIImageView的图像? - How can I blur an UIImageView's image? UITableViewAutomaticDimension工作,但是如何获得自动布局设置为的框架大小? - UITableViewAutomaticDimension is working but how do I get the frame Size the autolayout set it to?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM