Autolayout抱怨UIImageView的前导/尾随空间

Cap*_*GUY 0 objective-c storyboard ios swift

我在故事板中有一个UICollectionViewCell,里面有一个UIImageView.

的UICollectionViewCell size is width: 189, height: 239.ImageView具有以下约束:

Trailing Space to cell = 31
Leading Space to cell = 31
Bottom Space to cell =  25
Top Space to cell = 31
Run Code Online (Sandbox Code Playgroud)

运行时收到以下错误:

2014-11-28 19:53:33.934 AppName [1585:35698]无法同时满足约束条件.可能至少下列列表中的一个约束是您不想要的约束.试试这个:(1)看看每个约束并试着找出你不期望的东西; (2)找到添加了不需要的约束或约束的代码并修复它.(注意:如果您看到不理解的NSAutoresizingMaskLayoutConstraints,请参阅UIView属性translatesAutoresizingMaskIntoConstraints的文档)(

"<NSLayoutConstraint:0x7fa4a0d75220 H:[UIImageView:0x7fa4a0d743e0]-(31)-|   (Names: '|':UIView:0x7fa4a0d73d40 )>",
"<NSLayoutConstraint:0x7fa4a0d752c0 H:|-(32)-[UIImageView:0x7fa4a0d743e0]   (Names: '|':UIView:0x7fa4a0d73d40 )>",
"<NSAutoresizingMaskLayoutConstraint:0x7fa4a0d567a0 h=--& v=--& H:[UIView:0x7fa4a0d73d40(50)]>" )
Run Code Online (Sandbox Code Playgroud)

将尝试通过破坏约束来恢复NSLayoutConstraint:0x7fa4a0d75220 H:[UIImageView:0x7fa4a0d743e0] - (31) - | (名称:'|':UIView:0x7fa4a0d73d40)>

在UIViewAlertForUnsatisfiableConstraints上创建一个符号断点,以便在调试器中捕获它.在列出的UIView上的UIConstraintBasedLayoutDebugging类别中的方法也可能有所帮助.

我尝试以各种方式更改前导/尾随值(尝试偶数/奇数)但没有成功.是什么造成的?

rde*_*mar 6

这是iOS 8中的已知错误(请参阅此文章,仅在iOS 7上运行时,在Storyboard原型单元(Xcode 6,iOS 8 SDK)中发生UICollectionViewCell contentView框架的Autoresizing问题).单元格是您在故事板中设置的正确大小,但单元格的内容视图大小保持在50x50,这就是您获得约束错误的原因.在cellForItemAtIndexPath:中创建单元格后,可以通过添加此行来修复它,

cell.contentView.frame = cell.bounds
Run Code Online (Sandbox Code Playgroud)