gpt4 book ai didi

ios - Collection View 上奇怪的自动布局行为

转载 作者:技术小花猫 更新时间:2023-10-29 10:39:57 29 4
gpt4 key购买 nike

我遇到自动布局问题,控制台报告单元格中的 ImageView 存在问题:

RefreshCatalogue[31754:16177989] 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:0x7fa98103b740 V:[UIImageView:0x7fa9810375d0]-(0)-| (Names: '|':UIView:0x7fa9810371d0 )>",
"<NSLayoutConstraint:0x7fa98103b7e0 V:|-(0)-[UIImageView:0x7fa9810375d0] (Names: '|':UIView:0x7fa9810371d0 )>",
"<NSLayoutConstraint:0x7fa98103b8d0 UIImageView:0x7fa9810375d0.centerY == UIImageView:0x7fa981037490.centerY>",
"<NSLayoutConstraint:0x7fa98103ba60 UIImageView:0x7fa981037490.top == UIView:0x7fa9810371d0.topMargin + 71>",
"<NSAutoresizingMaskLayoutConstraint:0x7fa980d44a10 h=--& v=--& V:[UIView:0x7fa9810371d0(50)]>"
)

Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7fa98103b8d0 UIImageView:0x7fa9810375d0.centerY == UIImageView:0x7fa981037490.centerY>

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

问题是如果我这样做:

[self.collectionView reloadItemsAtIndexPaths:@[indexPath]];

即使 ImageView 似乎具有正确的框架,也没有任何显示,图像属性已设置。如果我重新加载整个 Collection View :

[self.collectionView reloadData];

错误仍然存​​在,但图像显示。代码在这里公开,有兴趣的可以看看: https://github.com/Ridiculous-Innovations/RefreshCatalogue

此外, Storyboard中的所有约束似乎都是蓝色的。知道可能导致问题的原因吗?

编辑:不用说所有元素,包括 ImageView 都在正确的位置(我调试了帧并设置了随机颜色)但是图像直到刷新才显示...有时单元格不显示完全显示

最佳答案

您遇到 UIImageView:0x7fa981037490.top == UIView:0x7fa9810371d0.topMargin + 71 和高度为 0 的父框架的问题(因此 imageview 高度必须为负,但这是不允许的),就像在调用 dequeueReusableCell 方法之后一样。这种情况下可能的解决方法是将嵌套 View 中最底部约束的优先级从 1000 更改为 999(垂直空间 - catalogueHeaderCell - ImageView 和垂直空间 - catalogueCell - 信息 View )。

关于ios - Collection View 上奇怪的自动布局行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32050365/

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