【发布时间】:2015-01-26 07:04:17
【问题描述】:
我正在开发一个项目,我们已经在 iOS 8 设备上测试了几周。今天我决定在 iOS 7.1 模拟器上测试它,我的应用记录了臭名昭著的约束错误:
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)
我了解自动布局,并且几乎不可能在此处演示示例(我需要将几乎整个项目放在这里,因为有许多执行自定义绘图的视图,许多与其他视图相关的约束等)。在 iOS 8 上,一切都很完美。在 iOS 7 上,我的一些视图的宽度/高度为零(已对其进行调试),而其他一些具有 与这些视图相关的宽度/高度的视图则完美绘制。我知道的一件事是,我已经仔细检查了没有涉及容器边距的限制。我知道它是 iOS 8 中的新功能。为什么可能是另一个原因?如果有帮助,这里是完整的跟踪:
(
"<NSLayoutConstraint:0x7a0e86b0 H:|-(0)-[UIView:0x7a17dfe0] (Names: '|':UIView:0x7a0e7a40 )>",
"<NSLayoutConstraint:0x7a0e86e0 H:[UIView:0x7a17dfe0]-(0)-| (Names: '|':UIView:0x7a0e7a40 )>",
"<NSAutoresizingMaskLayoutConstraint:0x79ecc850 h=--& v=--& H:[UIView:0x7a0e7a40(320)]>",
"<NSAutoresizingMaskLayoutConstraint:0x7a00add0 h=-&- v=-&- UITransitionView:0x79f9c110.width == UILayoutContainerView:0x79f9c070.width>",
"<NSAutoresizingMaskLayoutConstraint:0x7a00a550 h=-&- v=-&- UILayoutContainerView:0x79f9c070.width == UIViewControllerWrapperView:0x7a1b0340.width>",
"<NSAutoresizingMaskLayoutConstraint:0x7a009840 h=-&- v=-&- UIViewControllerWrapperView:0x7a1b0340.width == UINavigationTransitionView:0x7a18cfd0.width>",
"<NSAutoresizingMaskLayoutConstraint:0x7a008cc0 h=-&- v=-&- UINavigationTransitionView:0x7a18cfd0.width == UILayoutContainerView:0x7a0f17b0.width>",
"<NSAutoresizingMaskLayoutConstraint:0x7a008160 h=-&- v=-&- UILayoutContainerView:0x7a0f17b0.width == UIView:0x7a17dfe0.width>",
"<NSLayoutConstraint:0x7cdcc000 MyAppMoodTypeSelectionView:0x7f19ddf0.width == 2.5*MyAppFaceView:0x7f19e8b0.width>",
"<NSLayoutConstraint:0x7cde0380 MyAppMoodTypeSelectionView:0x7f19ddf0.width == 0.75*UIView:0x7cddfcf0.width>",
"<NSLayoutConstraint:0x7cde0470 MyAppRoundView:0x7a005e00.width == MyAppFaceView:0x7f19e8b0.width>",
"<NSAutoresizingMaskLayoutConstraint:0x7f1a0a20 h=-&- v=-&- UIView:0x7cddfcf0.width == UIViewControllerWrapperView:0x7cde15c0.width>",
"<NSAutoresizingMaskLayoutConstraint:0x7f1a10d0 h=-&- v=-&- UIViewControllerWrapperView:0x7cde15c0.width == UINavigationTransitionView:0x7cdd93a0.width>",
"<NSAutoresizingMaskLayoutConstraint:0x7f1a1750 h=-&- v=-&- UINavigationTransitionView:0x7cdd93a0.width == UILayoutContainerView:0x7a053c60.width>",
"<NSAutoresizingMaskLayoutConstraint:0x7f1a1e90 h=-&- v=-&- UILayoutContainerView:0x7a053c60.width == UIViewControllerWrapperView:0x7cdddc10.width>",
"<NSAutoresizingMaskLayoutConstraint:0x7f1a25e0 h=-&- v=-&- UIViewControllerWrapperView:0x7cdddc10.width == UITransitionView:0x79f9c110.width>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7cdcc000 MyAppMoodTypeSelectionView:0x7f19ddf0.width == 2.5*MyAppFaceView:0x7f19e8b0.width>
同样的应用程序在 iOS 8.1 上的所有约束都正确和满足的情况下运行得非常好,无论是在设备上还是在模拟器上。在 iOS 7.1 上,即使 在相同的屏幕尺寸上,我也会收到这些错误。
我尝试在所有视图上关闭translatesAutoresizingMaskIntoConstraints(除了主容器视图,否则屏幕变黑)。
原因是什么?除了新的容器边距限制之外,在自动布局方面,从 iOS 7 到 iOS 8 到底发生了什么变化?
更新:我的班级中有转换更改代码。显然,在 iOS 8 上,布局约束不受变换的影响,但在 iOS 7 上,它们受到变换的影响。不过仍在寻找解决方案,没有硬编码值。
【问题讨论】:
-
您可能会发现this 的答案很有趣。
-
@A-Live 我现在只是在看那个:)
标签: ios ios7 ios8 autolayout uikit