【发布时间】:2015-09-07 06:41:48
【问题描述】:
我有一个带有 Autolayout 和 Size Classes 的故事板。相当复杂的布局,不幸的是我无法确定如何在新项目中重现该问题。
但是有问题的视图被固定到屏幕的左右边缘,具有 750 优先级的约束(即|-(0@750)-[myView]-(0@750)-|,此外它具有大于或等于优先级为 1000 的约束(即|-(>=0)-[myView]-(>=0)-|)。这样做是为了限制iPad 上的宽度,因此有width <= 600 @1000 的宽度约束,以及容器中水平中心 约束。最重要的是视图的纵横比约束为 3:1。正如我所说,相当复杂。
Interface Builder 没有显示任何约束问题。 Xcode 布局预览在所有设备上都正确呈现。
当我运行应用程序时,iOS 告诉我它有冲突的约束。
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:0x7fd72853ff80 DMXKit.DipSwitchAssembly:0x7fd72990d0e0.width == 3*DMXKit.DipSwitchAssembly:0x7fd72990d0e0.height>",
"<NSLayoutConstraint:0x7fd728574e50 '_UITemporaryLayoutWidth' H:[DMXKit.DipSwitchAssembly:0x7fd72990d0e0(400)]>",
"<NSLayoutConstraint:0x7fd72856e9c0 V:[DMXKit.DipSwitchAssembly:0x7fd72990d0e0(133)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7ffb19798000 DMXKit.DipSwitchAssembly:0x7ffb1979a000.width == 3*DMXKit.DipSwitchAssembly:0x7ffb1979a000.height>
这会重复几次,具有完全相同(即相同的指针)约束。这也很奇怪,看起来约束并没有真正被打破。运行时,应用程序看起来 100% 正确。当我在 Xcode 视图调试器中查看应用程序时,地址为 0x7ffb19798000 的约束仍然存在,因此它从未被破坏。
_UITemporaryLayoutWidth 约束从何而来?显然我没有添加它。谷歌没有吐出任何关于_UITemporaryLayoutWidth 的有用信息。有人遇到过这样的问题吗?
【问题讨论】:
-
我在日志中也有很多这样的警告。虽然,它似乎并没有打破我的布局。我想知道这些
_UITemporaryLayoutWidths 是从哪里来的。
标签: ios autolayout nslayoutconstraint