SwiftUI |阻止TextField用键盘自动向上移动 [英] SwiftUI | Stop TextField from moving up with keyboard automatically
本文介绍了SwiftUI |阻止TextField用键盘自动向上移动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
自iOS14开始,我发现我的所有 TextField
都在键盘出现后自动上移.
Since iOS14 I have found that all my TextField
s are moving up automatically once the keyboard appears.
我还没有找到一种方法来阻止这种情况,我错过了什么吗?
I haven't found a way to stop this, have I missed something?
这是一个简单的演示代码:
Here is a simple Demo+Code:
演示:
代码:
import SwiftUI
struct ContentView: View {
@State private var textInput: String = ""
var body: some View {
TextField("Test", text: $textInput)
}
}
推荐答案
以下是您的方案的可能解决方案.经过Xcode 12/iOS 14的测试
Here is possible solution for your scenario. Tested with Xcode 12 / iOS 14
var body: some View {
VStack {
Spacer()
TextField("Test", text: $textInput)
Spacer()
}
.ignoresSafeArea(.keyboard, edges: .bottom)
}
这篇关于SwiftUI |阻止TextField用键盘自动向上移动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文