Невозможно одновременно удовлетворить ограничения с помощью клавиатуры и UIToolBar - PullRequest
1 голос
/ 18 июня 2020

У меня табличное представление, под которым есть текстовое представление. Я добавляю панель инструментов над клавиатурой, чтобы отобразить кнопку «Готово». Когда я нажимаю кнопку в строке, чтобы удалить строку, отображается проблема LayoutConstraints, как показано ниже. В следующем журнале также показан поток событий.

Я могу подтвердить, что эта проблема связана с панелью инструментов, если я удалю панель инструментов, эта проблема не появится.

Обсуждается аналогичный вопрос на https://github.com/hackiftekhar/IQKeyboardManager/issues/1616 Я пробовал несколько предложений оттуда, а именно

  • Отключить автокоррекцию для текстового просмотра -> Не сработало для меня

  • Используйте этот код для создания ToolBar, который у меня не работал

let toolBar = UIToolbar (frame: CGRect (origin: .zero, size: CGSize (ширина: UIScreen.main.bounds.size.width, высота: 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
    }
}

1 Ответ

2 голосов
/ 18 июня 2020

Это ошибка Apple, а не ваша. Игнорируй это. Это широко распространенная «проблема», но с этим ничего не поделаешь; визуальных повреждений не зарегистрировано. Это просто надоедливый дамп консоли.

...