隐藏UIImageView - 将宽度约束常量设置为0

时间:2014-04-16 14:03:38

标签: ios uiimageview autolayout

我在UIImageView子类中有一个CollectionViewCell。在CollectionViewCell XIB上我有一张图片。

有时我需要隐藏imageView。为了在单元配置方法中实现这一点,我隐藏了UIImageView,将宽度约束设置为0。

if (showImageView) {
    self.imageViewWidthConstraint.constant = self.defaultImageViewWidthConstraint;
    self.imageViewUsernameLabelHorizontalConstraint.constant = self.defaultImageViewUsernameLabelHorizontalConstraint;
} else {
    self.imageViewWidthConstraint.constant = 0;
    self.imageViewUsernameLabelHorizontalConstraint.constant = 0;
}

问题是在iOS7中,应用程序因不可满足的约束而崩溃

    Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
    "<NSLayoutConstraint:0x170890090 H:[UIImageView:0x1456dd970(0)]>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x170890090 H:[UIImageView:0x1456dd970(0)]>

我不明白我做错了什么。我仔细检查了我的XIB,但一切都很好。有一些规则,我不知道我不知道的约束常数变化?

我试图在XIB中将约束设置为0,我发现我没有打破其他约束。在这种情况下,应用程序可以正常运行。

0 个答案:

没有答案