项目作者: FranDepascuali

项目描述 :
A tool to understand constraints warnings. Nicer constraints warnings, with no setup needed.
高级语言: Swift
项目地址: git://github.com/FranDepascuali/ConstraintsMonitor.git
创建时间: 2020-05-25T18:56:19Z
项目社区:https://github.com/FranDepascuali/ConstraintsMonitor

开源协议:MIT License

下载


ConstraintsMonitor

A tool to understand constraints warnings, only adding it as a dependency.

#

Without ConstraintsMonitor:

  1. [LayoutConstraints] Unable to simultaneously satisfy constraints.
  2. Probably at least one of the constraints in the following list is one you don't want.
  3. Try this:
  4. (1) look at each constraint and try to figure out which you don't expect;
  5. (2) find the code that added the unwanted constraint or constraints and fix it.
  6. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
  7. (
  8. "<NSAutoresizingMaskLayoutConstraint:0x600003220d20 h=--& v=--& ConstraintsMonitor_Example.MyView:0x7fcdaff03e10.height == 896 (active)>",
  9. "<NSLayoutConstraint:0x600003220a50 UIView:0x7fcdaff031e0.height == 200 (active)>",
  10. "<NSLayoutConstraint:0x600003220410 V:|-(0)-[UIView:0x7fcdaff031e0] (active, names: '|':ConstraintsMonitor_Example.MyView:0x7fcdaff03e10 )>",
  11. "<NSLayoutConstraint:0x600003220aa0 V:[UIView:0x7fcdaff031e0]-(0)-[UIView:0x7fcdaff03fc0] (active)>",
  12. "<NSLayoutConstraint:0x600003220b90 UIView:0x7fcdaff03fc0.bottom == ConstraintsMonitor_Example.MyView:0x7fcdaff03e10.bottom (active)>",
  13. "<NSLayoutConstraint:0x600003220be0 UIView:0x7fcdaff03fc0.height == 0.2*ConstraintsMonitor_Example.MyView:0x7fcdaff03e10.height (active)>"
  14. )
  15. Will attempt to recover by breaking constraint
  16. <NSLayoutConstraint:0x600003220a50 UIView:0x7fcdaff031e0.height == 200 (active)>

With ConstraintsMonitor:

  1. [LayoutConstraints] Unable to simultaneously satisfy constraints.
  2. Probably at least one of the constraints in the following list is one you don't want.
  3. Try this:
  4. (1) look at each constraint and try to figure out which you don't expect;
  5. (2) find the code that added the unwanted constraint or constraints and fix it.
  6. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
  7. (
  8. "UIViewControllerWrapperView.MyView.height == 896.0 (Did you set translatesAutoresizingMaskIntoConstraints = false?)",
  9. "MyView.UIView.height == 200.0 ",
  10. "MyView.UIView.top == UIViewControllerWrapperView.MyView.top (constant: 0.0)",
  11. "MyView.UIView.top == UIView.bottom (constant: 0.0)",
  12. "MyView.UIView.bottom == UIViewControllerWrapperView.MyView.bottom (constant: 0.0)",
  13. "MyView.UIView.height == UIViewControllerWrapperView.MyView.height (multiplier: 0.200)"
  14. )
  15. Will attempt to recover by breaking constraint
  16. MyView.UIView.height == 200.0
  17. Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
  18. The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.

Why?

I was tired of looking for constraints issues and realizing what was really the issue, so I created this mini tool for printing nicer constraints

Installation

  1. pod 'ConstraintsMonitor'
  1. dependencies: [
  2. .package(url: "https://github.com/FranDepascuali/ConstraintsMonitor.git", from: "1.0.1")
  3. ]

Usage

Just by including this lib in your project, you will see nicer constraints warnings

Key Features

  • Use an identifier for the constraint if supplied.
  • Use the view identifier or the class name if the view is a subclass of UIView.
  • Show the parent view, so it’s easier to know where to locate the issue.

How does it work?

By overriding the description property of the NSLayoutConstraint involved, we have a nicer way of viewing constraints.

Author

You can check my blog at https://deep-thought.netlify.com/ or @FranDepascuali in twitter.

License

ConstraintsMonitor is available under the MIT license. See the LICENSE file for more info.