gpt4 book ai didi

ios - Autolayout 提示 UIImageView 的前导/尾随空间

转载 作者:行者123 更新时间:2023-11-28 09:46:53 25 4
gpt4 key购买 nike

我在 Storyboard中有一个 UICollectionViewCell,里面有一个 UIImageView。

UICollectionViewCell 大小为宽度:189,高度:239。 ImageView 具有以下约束:

Trailing Space to cell = 31
Leading Space to cell = 31
Bottom Space to cell = 25
Top Space to cell = 31

运行时出现以下错误:

2014-11-28 19:53:33.934 AppName[1585:35698] 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: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)]>" )

Will attempt to recover by breaking constraint NSLayoutConstraint:0x7fa4a0d75220 H:[UIImageView:0x7fa4a0d743e0]-(31)-| (Names: '|':UIView:0x7fa4a0d73d40 )>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger. The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in may also be helpful.

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

最佳答案

这是 iOS 8 中的一个已知错误(请参阅这篇文章,Autoresizing issue of UICollectionViewCell contentView's frame in Storyboard prototype cell (Xcode 6, iOS 8 SDK) happens when running on iOS 7 only)。该单元格是您在 Storyboard 中设置的正确大小,但单元格的内容 View 的大小保持在 50x50,这就是您收到约束错误的原因。在 cellForItemAtIndexPath: 中创建单元格后,可以通过添加此行来修复此问题:

cell.contentView.frame = cell.bounds

关于ios - Autolayout 提示 UIImageView 的前导/尾随空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27197813/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com