【发布时间】:2013-06-03 11:31:06
【问题描述】:
我的 iPad 项目的自动布局约束有问题,当我旋转设备时出现此错误:
2013-06-03 13:16:24.969 PDFViewer[7534:907] 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:0x1f5525e0 H:[UIScrollView:0x1f551910]-(970)-| (Names: '|':UIView:0x1f547740 )>",
"<NSLayoutConstraint:0x1f5525a0 H:|-(0)-[UIScrollView:0x1f551910] (Names: '|':UIView:0x1f547740 )>",
"<NSAutoresizingMaskLayoutConstraint:0x1f562520 h=--- v=--- H:[UIWindow:0x1f543890(768)]>",
"<NSAutoresizingMaskLayoutConstraint:0x1f560af0 h=-&- v=-&- UIView:0x1f547740.width == UIWindow:0x1f543890.width>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x1f5525e0 H:[UIScrollView:0x1f551910]-(970)-| (Names: '|':UIView:0x1f547740 )>
好的,有些约束是有争议的,但我自己没有设置任何约束,它们都是在 Interface Builder 中自动设置的,我无法删除它们。我想要的很简单,一个滚动视图,具有固定的宽度和 100% 的高度,以及一个集合视图,具有剩余的宽度和 100% 的高度。
自动布局让我发疯,有什么想法吗?
编辑:这是我在 IB 中定义的约束
【问题讨论】:
-
试试
[self.view setTranslatesAutoresizingMaskIntoConstraints:NO]。 Read the docs 了解更多详情。 -
感谢 PartiallyFinite 但它似乎没有任何改变。
-
您还应该检查您的约束并确保它们不会相互冲突。你有这么多,可能有一个公平的机会,不可能同时执行其中两个。您收到错误的原因是因为它试图强制执行您定义但不能执行的所有约束。
-
是的,有很多限制,但我不能删除它们。
标签: ios autolayout