SwiftUI文本编辑器如何隐藏键盘
我对TextEditor有问题,在TextEditor上编辑文本后,我无法隐藏键盘SwiftUI文本编辑器如何隐藏键盘,swiftui,text-editor,Swiftui,Text Editor,我对TextEditor有问题,在TextEditor上编辑文本后,我无法隐藏键盘 @State var monTexte: String = " var body: some View { VStack { Spacer() .frame(height :15) .clipped() Text("Project ")
@State var monTexte: String = "
var body: some View {
VStack {
Spacer()
.frame(height :15)
.clipped()
Text("Project ")
.font(Font.system(size: 39.00))
.fontWeight(.black)
.foregroundColor(Color.white)
.multilineTextAlignment(.center)
.padding(.all, 16.0)
.clipped()
TextEditor(text: $monTexte)
.keyboardType(.alphabet)
.font(.subheadline)
.padding(.horizontal)
.font(Font.system(size: 38.00))
.frame(minWidth: 10, maxWidth: .infinity, minHeight: 10, maxHeight: 200, alignment: .topLeading)
.border(Color.black)
.clipped()
}
}
}
我发现了一种方法,可以使用textfield隐藏键盘,但不使用TextEditor
你能帮我吗?谢谢你Asperi它的工作原理是使用以下代码:
var body: some View {
VStack {
Spacer()
.frame(height :15)
.clipped()
Text("Project ")
.font(Font.system(size: 39.00))
.fontWeight(.black)
.foregroundColor(Color.white)
.multilineTextAlignment(.center)
.padding(.all, 16.0)
.clipped()
HStack {
Spacer()
Button("Close Keyboard") {
UIApplication.shared.endEditing()
}.font(Font.system(size: 20))
.foregroundColor(Color.blue)
}.clipped()
TextEditor(text: $monTexte)
.keyboardType(.alphabet)
.font(.subheadline)
.padding(.horizontal)
.font(Font.system(size: 38.00))
.frame(minWidth: 10, maxWidth: .infinity, minHeight: 10, maxHeight: 200, alignment: .topLeading)
.border(Color.black)
.clipped()
}
}
}
//----------------------------------------------------//
// Masquer le clavier
//----------------------------------------------------//
extension UIApplication {
func endEditing() {
sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
}
}```
您如何定义编辑后的瞬间,即您希望在哪个事件中隐藏键盘?例如,使用特定按钮或使用键盘上的键返回,但未找到隐藏键盘的功能。文本编辑器中的键返回生成新行。它不是文本字段,但对于某些按钮,您可以使用类似中的方法。