我看到一个错误出现在我的调试器日志:
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x191f0920 H:[MPKnockoutButton:0x17a876b0]-(34)-[MPDetailSlider:0x17a8bc50](LTR)>
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.
我怎么能骗过那个电话?它没有出现在我的代码的任何地方。
我想我的问题是当我看到这样的东西时:
(
"<NSLayoutConstraint:0x600002faf7a0 'UISV-alignment' UIStackView:0x7fcdda716770.top == UIStackView:0x7fcdda7291d0.top (active)>",
"<NSLayoutConstraint:0x600002f84dc0 'UISV-canvas-connection' UILayoutGuide:0x6000035a8620'UIViewLayoutMarginsGuide'.top == UILabel:0x7fcdda716900.top (active)>",
"<NSLayoutConstraint:0x600002f8dfe0 'UISV-spacing' V:[UIImageView:0x7fcdda7170c0]-(2)-[UIStackView:0x7fcdda7291d0] (active)>",
"<NSLayoutConstraint:0x600002f84e60 'UISV-spacing' V:[UILabel:0x7fcdda716900]-(2)-[UIImageView:0x7fcdda7170c0] (active)>",
"<NSLayoutConstraint:0x600002f84c80 'UIView-topMargin-guide-constraint' V:|-(20)-[UILayoutGuide:0x6000035a8620'UIViewLayoutMarginsGuide'] (active, names: '|':UIStackView:0x7fcdda716770 )>"
)
我猜,恶心。他们并不指望我处理这些垃圾……但也许这就是我们所能得到的,也许并没有那么糟糕。
让我们稍微分解一下,代码指的是约束的id。实际上,你可以通过像这样简单地打印约束来找出它们对应的约束:
print("my Constraint", ibOutletConstraint)
你会得到:
my Constraint Optional(<NSLayoutConstraint:0x600001625a90 UIStackView:0x7fdca0c0d1f0.width == 2*UIStackView: 0x7fcdda716770.width (inactive)>)
现在我可以获取:0x7fcdda716770并搜索输出以将其与所讨论的约束匹配。它很乏味,当然也不迷人,但这是一种逐步打破它的方法。我认为苹果应该更清楚地说明哪个约束存在问题。