Xcode 版本 12.5 (12E262) / Swift 布局约束错误 - tableview with dynamic sizing textview

问题描述

我有一个表格视图,它具有动态调整大小的单元格 - 因为它们包含一个文本视图。一切都显示正确,但我收到了一些顽固的约束错误

我尝试以我能想到的各种方式修改删除,但它们要么持续存在,要么破坏功能(即,删除错误会破坏功能

Tableview Cell causing errors

错误似乎指向底部“任务”单元格的问题。

这些是我用于底部单元格的约束。

Constraints for bottom cell

以下错误

[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. 
(
    "<NSLayoutConstraint:0x282221590 UITableViewCellContentView:0x106079640.bottom == UITextView:0x1058cc000.bottomMargin + 8   (active)>","<NSLayoutConstraint:0x282221630 V:|-(2)-[UITextView:0x1058cc000]   (active,names: '|':UITableViewCellContentView:0x106079640 )>","<NSLayoutConstraint:0x282222170 'UIView-bottomMargin-guide-constraint' V:[UILayoutGuide:0x283818a80'UIViewLayoutMarginsGuide']-(8)-|   (active,names: '|':UITextView:0x1058cc000 )>","<NSLayoutConstraint:0x282221e50 'UIView-Encapsulated-Layout-Height' UITableViewCellContentView:0x106079640.height == 0   (active)>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x282222170 'UIView-bottomMargin-guide-constraint' V:[UILayoutGuide:0x283818a80'UIViewLayoutMarginsGuide']-(8)-|   (active,names: '|':UITextView:0x1058cc000 )>

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.

这可能只是一个错误还是我做错了什么?

我也试过 wtfautolayout.com,结果也有点令人困惑。

感谢任何帮助或想法

谢谢

解决方法

我推荐使用堆栈视图,你会节省一些约束,当然设计也会更好看一点,你的错误提到它是bottom = task text view.bottommargin + 8的约束。

>

同样,在设计屏幕上,您的约束可能会显示为红色,它会告诉您与您的设计相矛盾或不满意的前两个。

,

我设法通过更改约束之一的优先级来修复错误

enter image description here

enter image description here

一个来自 Facebook 群组的好心人给我发送了这个有用的链接:

http://aplus.rs/2017/one-solution-for-90pct-auto-layout/?fbclid=IwAR2bG95eNQScExFUtjL1H5dOrzjY0FTrScET--hcttzYP3hyDJVbiRipfOA