Swiftui TextField";简介;轻触键盘快捷界面(iOS 14)
当您使用Swiftui TextField";简介;轻触键盘快捷界面(iOS 14),swiftui,keyboard,textfield,ios14,Swiftui,Keyboard,Textfield,Ios14,当您使用TextField在SwiftUI中按下intro和键盘时,是否尝试过处理事件 TextField("type your name here", text: $yourName) 我如何知道用户何时按“介绍”按钮关闭键盘 非常感谢您 声明文本字段后,添加一个闭包并用以下代码填充:UIApplication.shared.keyWindow?.endEditing(true) 所以总体上看 TextField($yourText){ UIApplication
TextField
在SwiftUI
中按下intro
和键盘
时,是否尝试过处理事件
TextField("type your name here", text: $yourName)
我如何知道用户何时按“介绍”按钮关闭键盘
非常感谢您强>
声明
文本字段后,添加一个闭包并用以下代码填充:UIApplication.shared.keyWindow?.endEditing(true)
所以总体上看
TextField($yourText){
UIApplication.shared.keyWindow?.endEditing(true)
}
这段视频在8点左右解释了这一点
您可以使用TextField
中的onCommit
参数。以下是一个例子:
TextField("type your name here", text: $yourName, onCommit: {
print("return key pressed")
})
从文件中:
/// [...]
/// - onCommit: An action to perform when the user performs an action
/// (for example, when the user presses the Return key) while the text
/// field has focus.
public init(_ titleKey: LocalizedStringKey, text: Binding<String>, onEditingChanged: @escaping (Bool) -> Void = { _ in }, onCommit: @escaping () -> Void = {})
//[…]
///-onCommit:用户执行操作时要执行的操作
///(例如,当用户按下返回键时)文本
///场有焦点。
public init(uTitleKey:LocalizedStringKey,text:Binding,onEditingChanged:@escaping(Bool)->Void={in},onCommit:@escaping()->Void={})
onCommit允许您在用户按“返回键”时进行处理,这正是我要找的。。。不管怎样,我真的很感谢你的回答,非常感谢!