У меня проблема с автоматической компоновкой с помощью SnapKit.Я добавил UITextView в UITableViewCell и хочу, чтобы ячейка расширялась по мере того, как расширяется текстовое представление, когда пользователь добавляет контент.Однако в действительности, когда текстовое представление пытается раскрыться, ограничения ячейки нарушаются.Вот мой код:
TextFieldTableViewCell:
import UIKit
class TextFieldTableViewCell: FieldTableViewCell {
let textView = EditableTextView()
override func setUpViews() {
super.setUpViews()
setUpTextView()
}
private func setUpTextView() {
contentView.addSubview(textView)
textView.setContentHuggingPriority(UILayoutPriority(rawValue: 10000), for: .vertical)
textView.setContentCompressionResistancePriority(UILayoutPriority(rawValue: 10000), for: .vertical)
textView.snp.makeConstraints { make in
make.top.equalTo(fieldLabel.snp.bottom).offset(margin)
make.leading.equalToSuperview().offset(margin)
make.trailing.equalToSuperview().offset(-margin)
make.bottom.equalToSuperview().offset(-margin)
}
}
}
EditableTextView:
import UIKit
class EditableTextView: UITextView {
override func didMoveToSuperview() {
super.didMoveToSuperview()
isEditable = true
isScrollEnabled = false
}
}
А вот и моя ошибка:
2019-06-20 18:23:10.276724-0500 Campaign Detective[1127:169808] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /private/var/containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles
2019-06-20 18:23:10.278517-0500 Campaign Detective[1127:169808] [MC] Reading from public effective user settings.
2019-06-20 18:23:13.479469-0500 Campaign Detective[1127:169808] [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.
(
"<NSContentSizeLayoutConstraint:0x2831c90e0 Campaign_Detective.EditableTextView:0x140813200'Yeah I\U2019ll call them later...'.height == 86 Hug:10000 CompressionResistance:10000 (active)>",
"<SnapKit.LayoutConstraint:0x2831f82a0@FieldTableViewCell.swift#37 UILabel:0x13fb03540.top == UITableViewCellContentView:0x13fb03830.top + 15.0>",
"<SnapKit.LayoutConstraint:0x2831d1740@TextFieldTableViewCell.swift#20 Campaign_Detective.EditableTextView:0x140813200.top == UILabel:0x13fb03540.bottom + 15.0>",
"<SnapKit.LayoutConstraint:0x2831d1920@TextFieldTableViewCell.swift#23 Campaign_Detective.EditableTextView:0x140813200.bottom == UITableViewCellContentView:0x13fb03830.bottom - 15.0>",
"<NSLayoutConstraint:0x2836b5040 'UIView-Encapsulated-Layout-Height' UITableViewCellContentView:0x13fb03830.height == 123.333 (active)>"
)
Will attempt to recover by breaking constraint
<NSContentSizeLayoutConstraint:0x2831c90e0 Campaign_Detective.EditableTextView:0x140813200'Yeah I'll call them later...'.height == 86 Hug:10000 CompressionResistance:10000 (active)>
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.
Размер ячейки никогда не изменяется, поскольку ограничение UITableViewCellContentView:0x13fb03830.height
не изменяется.Разве это не должно быть изменено системой на новую расчетную высоту?Когда я устанавливаю .priority(.high)
для каждого ограничения, оно все равно не работает.