SwiftUI | Stop TextField from moving up with keyboard automatically

Viewed 2251

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 Answers

Here is possible solution for your scenario. Tested with Xcode 12 / iOS 14

demo

var body: some View {
    VStack {
        Spacer()
        TextField("Test", text: $textInput)
        Spacer()
    }
    .ignoresSafeArea(.keyboard, edges: .bottom)
}
Related