ios - 无法同时满足键盘和 UIToolBar 的约束

标签 ios swift uitextview uitoolbar

我有表格 View ,下面是 TextView 。我在键盘上方添加了一个工具栏来显示完成按钮。当我点击一行中的按钮以删除该行时,它会显示如下所示的 LayoutConstraints 问题。以下日志还显示了事件的流程。
我可以确认此问题与工具栏有关,如果我删除工具栏,则不会出现此问题。
类似的问题在 https://github.com/hackiftekhar/IQKeyboardManager/issues/1616 上讨论过
我从那里尝试了一些建议。

  • 禁用 TextView 的自动更正 -> 对我不起作用
  • 使用此代码创建对我不起作用的 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
        }
    }
    

    最佳答案

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

    关于ios - 无法同时满足键盘和 UIToolBar 的约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62455042/

    相关文章:

    swift - tvOS 检查当前聚焦的 ui 元素是否是 CollectionViewCell

    ios - 在 UITextView 长文本中添加多张图片

    ios - UITextView 在检测到 Action 时更改字体

    android - 如何在真实设备上打开 react-native 的开发菜单

    ios - uibarbuttonitem 色调颜色不是白色,当我将它设置为

    iphone - 我可以获取有关通知 (apn) 的信息吗

    ios - 动态选择 UIPicker 行

    ios - 对象从字典数组到数组

    ios - 如果启用了编辑模式,如何禁用 textview 的 uikeyboard

    ios - Spritekit 如何根据触摸和按住的位置运行 SKAction