ConstraintsMonitor
一个用于理解约束警告的工具,仅作为依赖项添加。
没有 ConstraintsMonitor
[LayoutConstraints] 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)
(
"<NSAutoresizingMaskLayoutConstraint:0x600003220d20 h=--& v=--& ConstraintsMonitor_Example.MyView:0x7fcdaff03e10.height == 896 (active)>",
"<NSLayoutConstraint:0x600003220a50 UIView:0x7fcdaff031e0.height == 200 (active)>",
"<NSLayoutConstraint:0x600003220410 V:|-(0)-[UIView:0x7fcdaff031e0] (active, names: '|':ConstraintsMonitor_Example.MyView:0x7fcdaff03e10 )>",
"<NSLayoutConstraint:0x600003220aa0 V:[UIView:0x7fcdaff031e0]-(0)-[UIView:0x7fcdaff03fc0] (active)>",
"<NSLayoutConstraint:0x600003220b90 UIView:0x7fcdaff03fc0.bottom == ConstraintsMonitor_Example.MyView:0x7fcdaff03e10.bottom (active)>",
"<NSLayoutConstraint:0x600003220be0 UIView:0x7fcdaff03fc0.height == 0.2*ConstraintsMonitor_Example.MyView:0x7fcdaff03e10.height (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x600003220a50 UIView:0x7fcdaff031e0.height == 200 (active)>
有 ConstraintsMonitor
[LayoutConstraints] 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)
(
"UIViewControllerWrapperView.MyView.height == 896.0 (Did you set translatesAutoresizingMaskIntoConstraints = false?)",
"MyView.UIView.height == 200.0 ",
"MyView.UIView.top == UIViewControllerWrapperView.MyView.top (constant: 0.0)",
"MyView.UIView.top == UIView.bottom (constant: 0.0)",
"MyView.UIView.bottom == UIViewControllerWrapperView.MyView.bottom (constant: 0.0)",
"MyView.UIView.height == UIViewControllerWrapperView.MyView.height (multiplier: 0.200)"
)
Will attempt to recover by breaking constraint
MyView.UIView.height == 200.0
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.
为什么?
我厌倦了寻找约束问题,并意识到真正的問題所在,因此我创建了这个小工具来打印更漂亮的约束信息。
安装
ConstraintsMonitor可通过CocoaPods获取。要安装它,只需将以下行添加到Podfile中
pod 'ConstraintsMonitor'
用法
仅通过拥有这个库,你将看到更漂亮的约束警告
主要功能
- 如果提供,请使用约束标识符。
- 如果视图是 UIView 的子类,请使用视图标识符或类名。
- 显示父视图,这样更容易找到问题所在的位置。
它是如何工作的?
通过重写有关联的 NSLayoutConstraint
的描述属性,我们有一种更好的方式来查看约束。
作者
您可以在我的博客 https://deep-thought.netlify.com/ 或推特上 @FranDepascuali 找到我。
许可协议
ConstraintsMonitor 在 MIT 许可证下可用。有关更多信息,请参阅 LICENSE 文件。