问题
Since iOS14 I have found that all my TextFields 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:
Demo:

Code:
import SwiftUI
struct ContentView: View {
@State private var textInput: String = ""
var body: some View {
TextField("Test", text: $textInput)
}
}
回答1:
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)
}
来源:https://stackoverflow.com/questions/64292534/swiftui-stop-textfield-from-moving-up-with-keyboard-automatically