无法同时满足键盘和 UIToolBar 的约束 [英] Unable to simultaneously satisfy constraints with keyboard and UIToolBar

查看:43
本文介绍了无法同时满足键盘和 UIToolBar 的约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有表格视图,下面有文本视图.我在键盘上方添加了一个工具栏来显示完成按钮.当我点击一行中的按钮以删除该行时,它会显示如下所示的 LayoutConstraints 问题.以下日志也显示了事件的流程.

I've table view below which I've text view. I'm adding a tool bar above keyboard to show Done button. When I tap on a button in a row to delete the row it shows LayoutConstraints issue as shown below. Following log also shows the flow of event.

我可以确认这个问题与工具栏有关,如果我删除工具栏,则不会出现此问题.

I can confirm that this issue is related with tool bar, if I remove tool bar then this problem doesn't appear.

https://github.com/hackiftekhar/IQKeyboardManager/issues/上讨论了类似的问题1616我已经尝试了一些建议,即.

Similar issue is discussed on https://github.com/hackiftekhar/IQKeyboardManager/issues/1616 I've tried few suggestions from there viz.

  • 禁用文本视图的自动更正 -> 对我不起作用

  • Disable auto correct for text view -> Didn't work for me

使用此代码创建对我不起作用的工具栏

Use this code for creating ToolBar which didn't work for me

let toolBar = UIToolbar(frame: CGRect(origin: .zero, size: CGSize(width: UIScreen.main.bounds.size.width, height: 44.0)))

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
    }
}

推荐答案

这是 Apple 的错误,不是你的.忽略它.这是一个普遍存在的问题",但没有什么可做的;没有视觉伤害记录.这只是一个烦人的控制台转储.

This is Apple's bug, not yours. Ignore it. It's a widespread "issue" but there's nothing to be done about it; no visual harm is registered. It's just an annoying console dump.

这篇关于无法同时满足键盘和 UIToolBar 的约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆