ios - 无法同时满足键盘和 UIToolBar 的约束
问题描述
我有表格视图,下面有文本视图。我在键盘上方添加了一个工具栏来显示完成按钮。当我连续点击一个按钮以删除该行时,它会显示 LayoutConstraints 问题,如下所示。以下日志还显示了事件的流程。
我可以确认此问题与工具栏有关,如果我删除工具栏则不会出现此问题。
在https://github.com/hackiftekhar/IQKeyboardManager/issues/1616上讨论了类似的问题, 我从那里尝试了一些建议。
禁用文本视图的自动更正 -> 对我不起作用
使用此代码创建对我不起作用的 ToolBar
let toolBar = UIToolbar(frame: CGRect(origin: .zero, size: CGSize(width: UIScreen.main.bounds.size.width, height: 44.0)))
有什么修复吗?
textViewShouldBeginEditing
textViewDidBeginEditing
deleteButtonTapped
textViewDidEndEditing
textViewShouldBeginEditing
[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:0x280c45f90 'accessoryView.bottom' _UIRemoteKeyboardPlaceholderView:0x10df221b0.bottom == _UIKBCompatInputView:0x10f819ff0.top (active)>",
"<NSLayoutConstraint:0x280c66cb0 'assistantHeight' TUISystemInputAssistantView:0x10aa64390.height == 45 (active)>",
"<NSLayoutConstraint:0x280c44500 'assistantView.bottom' TUISystemInputAssistantView:0x10aa64390.bottom == _UIKBCompatInputView:0x10f819ff0.top (active)>",
"<NSLayoutConstraint:0x280c444b0 'assistantView.top' V:[_UIRemoteKeyboardPlaceholderView:0x10df221b0]-(0)-[TUISystemInputAssistantView:0x10aa64390] (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x280c444b0 'assistantView.top' V:[_UIRemoteKeyboardPlaceholderView:0x10df221b0]-(0)-[TUISystemInputAssistantView:0x10aa64390] (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.
textViewDidBeginEditing
textViewDidEndEditing
添加完成按钮的代码。
override func viewDidLoad() {
super.viewDidLoad()
//...
self.textView.addDoneButton(title: "Done", target: self, selector: #selector(tapDone(sender:)))
}
extension UITextView {
// Add done button above keyboard
func addDoneButton(title: String, target: Any, selector: Selector) {
let toolBar = UIToolbar(frame: CGRect(x: 0.0,
y: 0.0,
width: UIScreen.main.bounds.size.width,
height: 44.0))
toolBar.backgroundColor = .toolBarBackground
let flexible = UIBarButtonItem(barButtonSystemItem: .fixedSpace, target: nil, action: nil)
let barButton = UIBarButtonItem(title: title, style: .plain, target: target, action: selector)
barButton.setTitleTextAttributes([NSAttributedString.Key.font : UIFont.bodyBold, NSAttributedString.Key.foregroundColor : UIColor.purpleColour], for: [])
toolBar.setItems([flexible, barButton], animated: false)
self.inputAccessoryView = toolBar
}
}
解决方案
这是苹果的错误,不是你的。忽略它。这是一个普遍的“问题”,但对此无能为力;没有记录到视觉伤害。这只是一个烦人的控制台转储。
推荐阅读
- java - MPAndroidChart 折线图在到达中途点后停止显示新数据
- javascript - 模态和 JS 错误 - 错误未捕获类型错误:无法读取 null 的属性“classList”
- rest - 调用 SOAP 服务的 MuleSoft REST API
- javascript - 如何将我的 TensorFlow saved_model.pb 转换为 Javascript?
- java - 如何让 Gradle 与 javaFX 和 mongoDB 一起运行?
- javascript - 将 HTML 字符串转换为 Javascript 文档说明
- java - 休眠单向一对多关系导致重复
- java - 我可以根据要构建的操作系统在 XML .classpath 文件中选择不同的 .jar 文件吗?
- git - 关于将大型 tfvc 存储库迁移到 git 的想法
- https - 私有 gke 集群和外部 HTTPS 负载均衡器运行状况检查失败