【发布时间】:2015-11-10 02:07:49
【问题描述】:
我的自动布局有问题,控制台报告我在单元格中的图像视图有问题:
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]];
即使图像视图似乎有正确的框架,也没有任何显示,图像属性已设置。 如果我重新加载整个集合视图:
[self.collectionView reloadData];
错误仍然存在,但图像显示。代码在这里开放,有兴趣的人可以看看: https://github.com/Ridiculous-Innovations/RefreshCatalogue
此外,故事板中的所有约束似乎都是蓝色的。知道可能导致问题的原因吗?
编辑:不用说,包括图像视图在内的所有元素都在正确的位置(我确实调试了帧并设置了随机颜色)但图像直到刷新才显示......有时单元格不会完全显示
【问题讨论】:
-
尝试删除约束并添加它们。尝试使用优先级。
-
不要把所有的约束都加进去,这样在改变设备布局的时候就不能全部满足
-
错误消息说:“如果您看到 NSAutoresizingMaskLayoutConstraints...” 那么,您正在看到它。这是一个大问题。您可能忘记将此视图的
translatesAutoresizingMaskIntoContraints设置为 NO。 (但我没有检查你的代码;仅仅 50 个赏金点,我不会涉足你的整个代码。把你的整个代码像意大利面条一样扔在墙上,并希望有人为你修复它有点粗鲁。 ..) -
感谢有关 translatesAutoresizingMaskIntoContraints 的提示,将检查...不幸的是,不得不说您的其余评论是不必要的,没有建设性的,甚至有点自大...我以前帮助过人们并将代码引用作为任何人都可以在需要时使用的附加信息,并且所有这些都不需要赏金。
-
检查了您的项目 - 由于缺少
LUIFramework,它无法构建。
标签: ios objective-c xcode autolayout uicollectionview