用于键盘输入AccessoryView的简单UIToolar的布局约束错误

Layout Constraint Errors with simple UIToolar for keyboard inputAccessoryView

我遇到了很多布局约束错误,所以我创建了一个新项目并使用 UIToolbar 和 UITextField 来尝试解决问题。即使是一个干净的项目,即使我没有覆盖 .inputAccessoryView 的任何约束,我仍然会遇到奇怪的错误。

代码如下(无故事板内容):

import UIKit

class ViewController: UIViewController {

    var aTextField = UITextField()

    override func viewDidLoad() {
        super.viewDidLoad()

        let aKeyboardToolBar = UIToolbar()

        // add buttons to the toolbar
        let prevButton = UIBarButtonItem(title: "PREV", style: .done, target: self, action: #selector(prevButtonTapped))
        let nextButton = UIBarButtonItem(title: "NEXT", style: .done, target: self, action: #selector(nextButtonTapped))
        let doneButton = UIBarButtonItem(title: "DONE", style: .done, target: self, action: #selector(doneButtonTapped))
        let flexibleSpace = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: self, action: nil)

        aKeyboardToolBar.setItems([prevButton, nextButton, flexibleSpace, doneButton], animated: true)
        aKeyboardToolBar.sizeToFit()

        // Add first textfield
        view.addSubview(aTextField)
        aTextField.backgroundColor = .orange
        aTextField.placeholder = "Blank TextField"
        aTextField.inputAccessoryView = aKeyboardToolBar

        // Layout first text field
        aTextField.translatesAutoresizingMaskIntoConstraints = false
        aTextField.topAnchor.constraint(equalTo: view.topAnchor, constant: 150).isActive = true
        aTextField.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 20).isActive = true
        aTextField.rightAnchor.constraint(equalTo: view.rightAnchor, constant: -20).isActive = true
    }



    @objc func prevButtonTapped() {
        print("prevButtonTapped")
    }



    @objc func nextButtonTapped() {
        print("nextButtonTapped")
    }



    @objc func doneButtonTapped() {
        view.endEditing(true)
    }

}

错误(KeyboardShifter 是项目名称):

2020-01-12 11:41:16.300180+1100 KeyboardShifter[1304:1170583] [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. 
    (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
    "<NSAutoresizingMaskLayoutConstraint:0x283f240a0 h=--& v=--& _UIToolbarContentView:0x10125fed0.width == 0   (active)>",
    "<NSLayoutConstraint:0x283f45d60 H:|-(0)-[_UIButtonBarStackView:0x10120fba0]   (active, names: '|':_UIToolbarContentView:0x10125fed0 )>",
    "<NSLayoutConstraint:0x283f45db0 _UIButtonBarStackView:0x10120fba0.trailing == _UIToolbarContentView:0x10125fed0.trailing   (active)>",
    "<NSLayoutConstraint:0x283f2ab70 'TB_Leading_Leading' H:|-(8)-[_UIModernBarButton:0x1011645b0'NEXT']   (active, names: '|':_UIButtonBarButton:0x1011641d0 )>",
    "<NSLayoutConstraint:0x283f2abc0 'TB_Trailing_Trailing' H:[_UIModernBarButton:0x1011645b0'NEXT']-(8)-|   (active, names: '|':_UIButtonBarButton:0x1011641d0 )>",
    "<NSLayoutConstraint:0x283f2b5c0 'UISV-canvas-connection' UILayoutGuide:0x282568460'UIViewLayoutMarginsGuide'.leading == _UIButtonBarButton:0x10115d760.leading   (active)>",
    "<NSLayoutConstraint:0x283f2b610 'UISV-canvas-connection' UILayoutGuide:0x282568460'UIViewLayoutMarginsGuide'.trailing == _UIButtonBarButton:0x1011650e0.trailing   (active)>",
    "<NSLayoutConstraint:0x283f2b840 'UISV-spacing' H:[_UIButtonBarButton:0x10115d760]-(0)-[UIView:0x101164060]   (active)>",
    "<NSLayoutConstraint:0x283f2b890 'UISV-spacing' H:[UIView:0x101164060]-(0)-[_UIButtonBarButton:0x1011641d0]   (active)>",
    "<NSLayoutConstraint:0x283f2b8e0 'UISV-spacing' H:[_UIButtonBarButton:0x1011641d0]-(0)-[UIView:0x101164f70]   (active)>",
    "<NSLayoutConstraint:0x283f2b930 'UISV-spacing' H:[UIView:0x101164f70]-(0)-[_UIButtonBarButton:0x1011650e0]   (active)>",
    "<NSLayoutConstraint:0x283f45bd0 'UIView-leftMargin-guide-constraint' H:|-(0)-[UILayoutGuide:0x282568460'UIViewLayoutMarginsGuide'](LTR)   (active, names: '|':_UIButtonBarStackView:0x10120fba0 )>",
    "<NSLayoutConstraint:0x283f45c70 'UIView-rightMargin-guide-constraint' H:[UILayoutGuide:0x282568460'UIViewLayoutMarginsGuide']-(0)-|(LTR)   (active, names: '|':_UIButtonBarStackView:0x10120fba0 )>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x283f2abc0 'TB_Trailing_Trailing' H:[_UIModernBarButton:0x1011645b0'NEXT']-(8)-|   (active, names: '|':_UIButtonBarButton:0x1011641d0 )>

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.
2020-01-12 11:41:16.301336+1100 KeyboardShifter[1304:1170583] [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. 
    (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
    "<NSAutoresizingMaskLayoutConstraint:0x283f240a0 h=--& v=--& _UIToolbarContentView:0x10125fed0.width == 0   (active)>",
    "<NSLayoutConstraint:0x283f45d60 H:|-(0)-[_UIButtonBarStackView:0x10120fba0]   (active, names: '|':_UIToolbarContentView:0x10125fed0 )>",
    "<NSLayoutConstraint:0x283f45db0 _UIButtonBarStackView:0x10120fba0.trailing == _UIToolbarContentView:0x10125fed0.trailing   (active)>",
    "<NSLayoutConstraint:0x283f2a490 'TB_Leading_Leading' H:|-(0)-[_UIModernBarButton:0x10115e6d0'PREV']   (active, names: '|':_UIButtonBarButton:0x10115d760 )>",
    "<NSLayoutConstraint:0x283f2a4e0 'TB_Trailing_Trailing' H:[_UIModernBarButton:0x10115e6d0'PREV']-(8)-|   (active, names: '|':_UIButtonBarButton:0x10115d760 )>",
    "<NSLayoutConstraint:0x283f2b5c0 'UISV-canvas-connection' UILayoutGuide:0x282568460'UIViewLayoutMarginsGuide'.leading == _UIButtonBarButton:0x10115d760.leading   (active)>",
    "<NSLayoutConstraint:0x283f2b610 'UISV-canvas-connection' UILayoutGuide:0x282568460'UIViewLayoutMarginsGuide'.trailing == _UIButtonBarButton:0x1011650e0.trailing   (active)>",
    "<NSLayoutConstraint:0x283f2b840 'UISV-spacing' H:[_UIButtonBarButton:0x10115d760]-(0)-[UIView:0x101164060]   (active)>",
    "<NSLayoutConstraint:0x283f2b890 'UISV-spacing' H:[UIView:0x101164060]-(0)-[_UIButtonBarButton:0x1011641d0]   (active)>",
    "<NSLayoutConstraint:0x283f2b8e0 'UISV-spacing' H:[_UIButtonBarButton:0x1011641d0]-(0)-[UIView:0x101164f70]   (active)>",
    "<NSLayoutConstraint:0x283f2b930 'UISV-spacing' H:[UIView:0x101164f70]-(0)-[_UIButtonBarButton:0x1011650e0]   (active)>",
    "<NSLayoutConstraint:0x283f45bd0 'UIView-leftMargin-guide-constraint' H:|-(0)-[UILayoutGuide:0x282568460'UIViewLayoutMarginsGuide'](LTR)   (active, names: '|':_UIButtonBarStackView:0x10120fba0 )>",
    "<NSLayoutConstraint:0x283f45c70 'UIView-rightMargin-guide-constraint' H:[UILayoutGuide:0x282568460'UIViewLayoutMarginsGuide']-(0)-|(LTR)   (active, names: '|':_UIButtonBarStackView:0x10120fba0 )>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x283f2a4e0 'TB_Trailing_Trailing' H:[_UIModernBarButton:0x10115e6d0'PREV']-(8)-|   (active, names: '|':_UIButtonBarButton:0x10115d760 )>

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.
2020-01-12 11:41:16.302024+1100 KeyboardShifter[1304:1170583] [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. 
    (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
    "<NSAutoresizingMaskLayoutConstraint:0x283f240a0 h=--& v=--& _UIToolbarContentView:0x10125fed0.width == 0   (active)>",
    "<NSLayoutConstraint:0x283f45d60 H:|-(0)-[_UIButtonBarStackView:0x10120fba0]   (active, names: '|':_UIToolbarContentView:0x10125fed0 )>",
    "<NSLayoutConstraint:0x283f45db0 _UIButtonBarStackView:0x10120fba0.trailing == _UIToolbarContentView:0x10125fed0.trailing   (active)>",
    "<NSLayoutConstraint:0x283f2b200 'TB_Leading_Leading' H:|-(8)-[_UIModernBarButton:0x1011652c0'DONE']   (active, names: '|':_UIButtonBarButton:0x1011650e0 )>",
    "<NSLayoutConstraint:0x283f2b250 'TB_Trailing_Trailing' H:[_UIModernBarButton:0x1011652c0'DONE']-(0)-|   (active, names: '|':_UIButtonBarButton:0x1011650e0 )>",
    "<NSLayoutConstraint:0x283f2b5c0 'UISV-canvas-connection' UILayoutGuide:0x282568460'UIViewLayoutMarginsGuide'.leading == _UIButtonBarButton:0x10115d760.leading   (active)>",
    "<NSLayoutConstraint:0x283f2b610 'UISV-canvas-connection' UILayoutGuide:0x282568460'UIViewLayoutMarginsGuide'.trailing == _UIButtonBarButton:0x1011650e0.trailing   (active)>",
    "<NSLayoutConstraint:0x283f2b840 'UISV-spacing' H:[_UIButtonBarButton:0x10115d760]-(0)-[UIView:0x101164060]   (active)>",
    "<NSLayoutConstraint:0x283f2b890 'UISV-spacing' H:[UIView:0x101164060]-(0)-[_UIButtonBarButton:0x1011641d0]   (active)>",
    "<NSLayoutConstraint:0x283f2b8e0 'UISV-spacing' H:[_UIButtonBarButton:0x1011641d0]-(0)-[UIView:0x101164f70]   (active)>",
    "<NSLayoutConstraint:0x283f2b930 'UISV-spacing' H:[UIView:0x101164f70]-(0)-[_UIButtonBarButton:0x1011650e0]   (active)>",
    "<NSLayoutConstraint:0x283f45bd0 'UIView-leftMargin-guide-constraint' H:|-(0)-[UILayoutGuide:0x282568460'UIViewLayoutMarginsGuide'](LTR)   (active, names: '|':_UIButtonBarStackView:0x10120fba0 )>",
    "<NSLayoutConstraint:0x283f45c70 'UIView-rightMargin-guide-constraint' H:[UILayoutGuide:0x282568460'UIViewLayoutMarginsGuide']-(0)-|(LTR)   (active, names: '|':_UIButtonBarStackView:0x10120fba0 )>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x283f2b250 'TB_Trailing_Trailing' H:[_UIModernBarButton:0x1011652c0'DONE']-(0)-|   (active, names: '|':_UIButtonBarButton:0x1011650e0 )>

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.
2020-01-12 11:41:16.302742+1100 KeyboardShifter[1304:1170583] [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. 
    (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
    "<NSAutoresizingMaskLayoutConstraint:0x283f24140 h=--& v=--& _UIToolbarContentView:0x10125fed0.height == 0   (active)>",
    "<NSLayoutConstraint:0x283f45e00 V:|-(0)-[_UIButtonBarStackView:0x10120fba0]   (active, names: '|':_UIToolbarContentView:0x10125fed0 )>",
    "<NSLayoutConstraint:0x283f45e50 _UIButtonBarStackView:0x10120fba0.bottom == _UIToolbarContentView:0x10125fed0.bottom   (active)>",
    "<NSLayoutConstraint:0x283f250e0 UIButtonLabel:0x101163420'PREV'.centerY == _UIModernBarButton:0x10115e6d0'PREV'.centerY + 1.5   (active)>",
    "<NSLayoutConstraint:0x283f2a670 'TB_Baseline_Baseline' _UIModernBarButton:0x10115e6d0'PREV'.lastBaseline == UILayoutGuide:0x28257c620'UIViewLayoutMarginsGuide'.bottom   (active)>",
    "<NSLayoutConstraint:0x283f2a6c0 'TB_Top_Top' V:|-(>=0)-[_UIModernBarButton:0x10115e6d0'PREV']   (active, names: '|':_UIButtonBarButton:0x10115d760 )>",
    "<NSLayoutConstraint:0x283f2a800 'UIButtonBar.maximumAlignmentSize' _UIButtonBarButton:0x10115d760.height == UILayoutGuide:0x282568460'UIViewLayoutMarginsGuide'.height   (active)>",
    "<NSLayoutConstraint:0x283f45c20 'UIView-bottomMargin-guide-constraint' V:[UILayoutGuide:0x282568460'UIViewLayoutMarginsGuide']-(0)-|   (active, names: '|':_UIButtonBarStackView:0x10120fba0 )>",
    "<NSLayoutConstraint:0x283f2a5d0 'UIView-bottomMargin-guide-constraint' V:[UILayoutGuide:0x28257c620'UIViewLayoutMarginsGuide']-(11)-|   (active, names: '|':_UIButtonBarButton:0x10115d760 )>",
    "<NSLayoutConstraint:0x283f45b80 'UIView-topMargin-guide-constraint' V:|-(0)-[UILayoutGuide:0x282568460'UIViewLayoutMarginsGuide']   (active, names: '|':_UIButtonBarStackView:0x10120fba0 )>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x283f250e0 UIButtonLabel:0x101163420'PREV'.centerY == _UIModernBarButton:0x10115e6d0'PREV'.centerY + 1.5   (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.
2020-01-12 11:41:16.303504+1100 KeyboardShifter[1304:1170583] [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. 
    (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
    "<NSAutoresizingMaskLayoutConstraint:0x283f24140 h=--& v=--& _UIToolbarContentView:0x10125fed0.height == 0   (active)>",
    "<NSLayoutConstraint:0x283f45e00 V:|-(0)-[_UIButtonBarStackView:0x10120fba0]   (active, names: '|':_UIToolbarContentView:0x10125fed0 )>",
    "<NSLayoutConstraint:0x283f45e50 _UIButtonBarStackView:0x10120fba0.bottom == _UIToolbarContentView:0x10125fed0.bottom   (active)>",
    "<NSLayoutConstraint:0x283f25810 UIButtonLabel:0x101164880'NEXT'.centerY == _UIModernBarButton:0x1011645b0'NEXT'.centerY + 1.5   (active)>",
    "<NSLayoutConstraint:0x283f2ad50 'TB_Baseline_Baseline' _UIModernBarButton:0x1011645b0'NEXT'.lastBaseline == UILayoutGuide:0x28257c700'UIViewLayoutMarginsGuide'.bottom   (active)>",
    "<NSLayoutConstraint:0x283f2ada0 'TB_Top_Top' V:|-(>=0)-[_UIModernBarButton:0x1011645b0'NEXT']   (active, names: '|':_UIButtonBarButton:0x1011641d0 )>",
    "<NSLayoutConstraint:0x283f2aee0 'UIButtonBar.maximumAlignmentSize' _UIButtonBarButton:0x1011641d0.height == UILayoutGuide:0x282568460'UIViewLayoutMarginsGuide'.height   (active)>",
    "<NSLayoutConstraint:0x283f45c20 'UIView-bottomMargin-guide-constraint' V:[UILayoutGuide:0x282568460'UIViewLayoutMarginsGuide']-(0)-|   (active, names: '|':_UIButtonBarStackView:0x10120fba0 )>",
    "<NSLayoutConstraint:0x283f2acb0 'UIView-bottomMargin-guide-constraint' V:[UILayoutGuide:0x28257c700'UIViewLayoutMarginsGuide']-(11)-|   (active, names: '|':_UIButtonBarButton:0x1011641d0 )>",
    "<NSLayoutConstraint:0x283f45b80 'UIView-topMargin-guide-constraint' V:|-(0)-[UILayoutGuide:0x282568460'UIViewLayoutMarginsGuide']   (active, names: '|':_UIButtonBarStackView:0x10120fba0 )>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x283f25810 UIButtonLabel:0x101164880'NEXT'.centerY == _UIModernBarButton:0x1011645b0'NEXT'.centerY + 1.5   (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.
2020-01-12 11:41:16.304192+1100 KeyboardShifter[1304:1170583] [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. 
    (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
    "<NSAutoresizingMaskLayoutConstraint:0x283f24140 h=--& v=--& _UIToolbarContentView:0x10125fed0.height == 0   (active)>",
    "<NSLayoutConstraint:0x283f45e00 V:|-(0)-[_UIButtonBarStackView:0x10120fba0]   (active, names: '|':_UIToolbarContentView:0x10125fed0 )>",
    "<NSLayoutConstraint:0x283f45e50 _UIButtonBarStackView:0x10120fba0.bottom == _UIToolbarContentView:0x10125fed0.bottom   (active)>",
    "<NSLayoutConstraint:0x283f25f40 UIButtonLabel:0x101165590'DONE'.centerY == _UIModernBarButton:0x1011652c0'DONE'.centerY + 1.5   (active)>",
    "<NSLayoutConstraint:0x283f2b3e0 'TB_Baseline_Baseline' _UIModernBarButton:0x1011652c0'DONE'.lastBaseline == UILayoutGuide:0x28257c7e0'UIViewLayoutMarginsGuide'.bottom   (active)>",
    "<NSLayoutConstraint:0x283f2b430 'TB_Top_Top' V:|-(>=0)-[_UIModernBarButton:0x1011652c0'DONE']   (active, names: '|':_UIButtonBarButton:0x1011650e0 )>",
    "<NSLayoutConstraint:0x283f2b570 'UIButtonBar.maximumAlignmentSize' _UIButtonBarButton:0x1011650e0.height == UILayoutGuide:0x282568460'UIViewLayoutMarginsGuide'.height   (active)>",
    "<NSLayoutConstraint:0x283f45c20 'UIView-bottomMargin-guide-constraint' V:[UILayoutGuide:0x282568460'UIViewLayoutMarginsGuide']-(0)-|   (active, names: '|':_UIButtonBarStackView:0x10120fba0 )>",
    "<NSLayoutConstraint:0x283f2b340 'UIView-bottomMargin-guide-constraint' V:[UILayoutGuide:0x28257c7e0'UIViewLayoutMarginsGuide']-(11)-|   (active, names: '|':_UIButtonBarButton:0x1011650e0 )>",
    "<NSLayoutConstraint:0x283f45b80 'UIView-topMargin-guide-constraint' V:|-(0)-[UILayoutGuide:0x282568460'UIViewLayoutMarginsGuide']   (active, names: '|':_UIButtonBarStackView:0x10120fba0 )>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x283f25f40 UIButtonLabel:0x101165590'DONE'.centerY == _UIModernBarButton:0x1011652c0'DONE'.centerY + 1.5   (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.

有什么想法吗?

改变

let aKeyboardToolBar = UIToolbar()

let aKeyboardToolBar = UIToolbar(frame:CGRect(x:0, y:0, width:100, height:100))

这样它就有 一些 大小可以在你给它内容时使用。

我得到了

Unable to simultaneously satisfy constraints

我的键盘 inputAccessoryView 中的 UIToolbar 出错,但我的 UIToolbar 的尺寸已经在实例化时定义:

@objc var accessoryDoneButton: UIBarButtonItem!
@objc var emptyButton: UIBarButtonItem!
@objc let accessoryToolBar = UIToolbar(frame: CGRect(x:0, y: 0,width:UIScreen.main.bounds.width, height:44))

我通过更改 UIToolBar 中的项目解决了我的问题:

    // Position dismiss button in the 3rd. space from the left side of toolbar.
//        self.accessoryToolBar.items = [self.emptyButton, self.emptyButton, self.emptyButton, self.accessoryDoneButton]
        self.accessoryToolBar.items = [self.accessoryDoneButton]
        self.symptomDescription.inputAccessoryView = self.accessoryToolBar

因为我不需要自动更正,所以我的解决方案只是设置

textField.autocorrectionType = .no

在我现在正在编写的应用程序中,用户可以在填充各种文本字段之间来回切换,这可能会破坏 UIToolbar 约束。

希望对大家有所帮助!