我在 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/