In this simple Hello World app (Xcode 14.3, iOS 14.4.1), adding a Toolbar item above the keyboard leads to constraints errors in the log when you tap the TextField. It does not seem to lead to any obvious errors in the UI.
Anyone have ideas on how to work around this?
struct ContentView: View {
@State private var foodName: String = ""
var body: some View {
VStack {
TextField("test", text: $foodName)
}
.padding()
.toolbar {
ToolbarItem(placement: .keyboard) {
Text("Test")
}
}
}
}
[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:0x28137d2c0 h=--& v=--& _UIToolbarContentView:0x143609e30.width == 0 (active)>",
"<NSLayoutConstraint:0x2813708c0 H:|-(16)-[_UIButtonBarStackView:0x143608ab0] (active, names: '|':_UIToolbarContentView:0x143609e30 )>",
"<NSLayoutConstraint:0x281370910 H:[_UIButtonBarStackView:0x143608ab0]-(16)-| (active, names: '|':_UIToolbarContentView:0x143609e30 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x281370910 H:[_UIButtonBarStackView:0x143608ab0]-(16)-| (active, names: '|':_UIToolbarContentView:0x143609e30 )>
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.