首页 > 解决方案 > UIView-Encapsulated-Layout-Width 和 LayoutConstraint

问题描述

运行应用程序时出现以下错误。我有什么样的视觉问题?

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.
2019-06-15 17:45:15.916490+0300 ...[3888:779219] [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. 
(
    "<SnapKit.LayoutConstraint:0x280cf51a0@MainTableViewController.swift#3209 ....DeviceTableViewCell:0x10c82cc00.width == 375.0>",
    "<NSLayoutConstraint:0x280be41e0 'UIView-Encapsulated-Layout-Width' ....DeviceTableViewCell:0x10c82cc00'cellId'.width == 0   (active)>"
)

Will attempt to recover by breaking constraint 
<SnapKit.LayoutConstraint:0x280cf51a0@MainTableViewController.swift#3209 ...DeviceTableViewCell:0x10c82cc00.width == 375.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.

 cell.snp.makeConstraints { (make) in
            make.top.equalTo(100)
            make.height.equalTo(205)
            make.width.equalTo(view.frame.width)
        }

标签: swift

解决方案


我认为你有 2 个特定的宽度约束cell,所以检查一下。

  • 去你的故事板。
  • 打开右侧菜单。
  • 在顶部单击尺寸检查器并检查您的约束。

在此处输入图像描述

或者尝试更改宽度约束的优先级。

make.width.equalTo(view.frame.width).priority(999)

推荐阅读