【发布时间】:2013-09-22 17:21:24
【问题描述】:
我有一个配置了自动布局的UIImageView 对象。我创建了约束,以便视图与其父视图保持恒定距离。在视觉格式中,它会是这样的:
@"V:|-[imageView]-|"
@"H:|-[imageView]-|"
但我也想保持底层图像的纵横比,所以我将UIViewContentModeScaleAspectFit分配给contentMode。
在我设置关联的CALayer 的cornerRadius 值之前,我认为一切正常:
self.imageView.layer.cornerRadius = 7;
self.imageView.layer.maskToBounds = YES;
现在当图像视图调整大小时,例如由于方向的变化,圆角会根据视图获得的新大小而丢失。原因是cornerRadius 适用于UIImageView(下方虚线框),但由于基础图像的大小也已调整为尊重contentMode(下方星号框),圆角不再可见:
--------------------------
| ********** |
| * * |
| * * |
| * * |
| ********** |
--------------------------
有没有办法防止这种行为?
【问题讨论】:
标签: ios autolayout cornerradius contentmode