我有一个带有缩放中心的UIImageView,所以它的大小根据内部的UIImage而变化,但是,通过设置一个nil UIImage,约束会中断,因为没有内容大小可以计算
如何使用nil UIImage处理自动布局(大小应更改为0,0)?
答案 0 :(得分:16)
问题是UIImageView
在没有设置图像时返回{-1,-1}作为intrinsicContentSize。使用UIImageView
的子类,实现如下:
@implementation MyImageView
- (CGSize)intrinsicContentSize
{
if (self.image)
{
return [super intrinsicContentSize];
}
return CGSizeZero;
}
@end
答案 1 :(得分:0)
将Content hugging priority
设为Required
(1000)。
更新:这个答案之前有效,但现在还没有用。 使用Nikita Ivaniushchenko 代替。