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

标签 ios uiimageview autolayout uisplitviewcontroller

我在 UISplitViewController 中的详细 View 的自动布局遇到了问题。我的 View 层次结构包含一个带有装饰元素的 UIImageView, ImageView 的固有大小似乎搞砸了其余控件的布局。

这些是我为 ImageView 指定的约束:

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

我想要的行为是调整 ImageView 的大小以填充其父 View ,如前两个约束所述。我看到的实际行为是 ImageView 仅占用其固有大小约束所描述的水平空间。它似乎也在改变其所有兄弟 View 的布局,就好像父 View 只是在与 ImageView 一样宽的矩形中布置 View 。

我认为将 ImageView 的拥抱优先级指定得尽可能低会让其他约束覆盖它以调整 ImageView 的大小。我在这里做错了什么?

最佳答案

所以,我终于找到了解决办法。

解决方案是将 superview 的 Hugging Priority 增加到 .defaultHigh 并将 UIImageView 的 Compression Resistance Priority 降低到 .defaultLow。这将使约束覆盖图像的固有尺寸。

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.

关于ios - 如何让自动布局覆盖 UIImageView 的固有大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24807474/

相关文章:

objective-c - 带有 resizableImage 选项的 UIImage

ios - TableView 在 API 请求更新模型之前加载单元格

ios - UIImageView 'unrecognized selector sent to instance' 难以捉摸的硬崩溃

ios - 如何围绕自定义蒙版创建描边?

ios - 以编程方式使用自动布局将图像定位到 View 的中心

ios - 属性不可用警告

ios - 动画化多个类似uiscrollviews的动画

ios - 如何快速裁剪圆孔中的缩放图像

ios - 将约束应用于 Facebook 登录按钮

ios - 如何在 Xcode6 中为新创建的约束禁用 "Relative to margin"选项