SwiftUI | Stop TextField from moving up with keyboard automatically [duplicate]

落爺英雄遲暮 提交于 2020-12-12 01:33:24

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!