这个问题最好用代码来描述。
struct ContentView: View {
enum FocusedField {
case type1
case type2
}
@State private var text: String = ""
@FocusState private var focusedField: FocusedField?
var body: some View {
TextField("Type 1", text: $text)
.focused($focusedField, equals: .type1)
.toolbar {
ToolbarItem(placement: .keyboard) {
TextField("Type 2", text: $text)
.focused($focusedField, equals: .type2)
.onSubmit {
focusedField = nil // This will switch to type1 instead of dismissing.
}
}
}
}
}
控制台会输出:
-[RTIInputSystemClient remoteTextInputSessionWithID:performInputOperation:] perform input operation requires a valid sessionID. inputModality = Keyboard, inputOperation = <null selector>, customInfoType = UIEmojiSearchOperations
public func HideKeyboard() {
#if canImport(UIKit)
UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
#endif
}