如何防止键盘在 SwiftUI 中推高视图? [英] How to prevent keyboard from pushing up the view in SwiftUI?
本文介绍了如何防止键盘在 SwiftUI 中推高视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是 SwiftUI 编程的新手,我已经创建了一个视图,但是一旦用户点击文本字段,键盘就会出现并且整个视图向上推,我该如何解决这个问题?
i am new to SwiftUI programming, i've made a view but once the user taps on the textfield the keyboard appears and the entire view pushes up, how do i fix this?
推荐答案
我相信你可以使用 .ignoresSafeArea(.keyboard)
我在 XCode 12.4 和模拟器 iOS 14.4 中测试了这段代码
I tested this code in XCode 12.4 and simulator iOS 14.4
struct ContentView: View {
var body: some View {
VStack {
Spacer()
Group {
Text("Content")
Text("Content")
Text("Content")
Text("Content")
Text("Content")
Text("Content")
Text("Content")
Text("Content")
Text("Content")
}
HStack{
Spacer()
TextField("INPUT", text: .constant("HERE IS INPUT"))
Spacer()
}
Group {
Text("Content")
Text("Content")
Text("Content")
Text("Content")
Text("Content")
Text("Content")
Text("Content")
Text("Content")
Text("Content")
}
Spacer()
}
.ignoresSafeArea(.keyboard)
}
}
这篇关于如何防止键盘在 SwiftUI 中推高视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文