Cuando tengo TextField dentro de ScrollView y lo toco, el teclado se muestra como se esperaba. Pero parece que TextField se movió lo suficiente para mostrar el área de entrada, pero quiero que se mueva lo suficiente para que sea visible en su totalidad. De lo contrario, parece recortado. No pude encontrar una manera de cambiar este comportamiento.
struct ContentView: View { @State var text:String = "" var body: some View { ScrollView { VStack(spacing: 10) { ForEach(1...12, id: \.self) { Text("\($0)…") .frame(height:50) } TextField("Label..", text: self.$text) .padding(10) .background(.white) .cornerRadius(10) .overlay( RoundedRectangle(cornerRadius: 10) .stroke(.blue, lineWidth: 1) ) } .padding() .background(.red) } } }Use un modificador .safeAreaInset.
@State var text:String = "" var body: some View { ScrollView { VStack(spacing: 10) { ForEach(1...12, id: \.self) { Text("\($0)…") .frame(height:50) } TextField("Label..", text: self.$text) .padding(10) .background(.white) .cornerRadius(10) .overlay( RoundedRectangle(cornerRadius: 10) .stroke(.blue, lineWidth: 1) ) } .padding() .background(.red) }.safeAreaInset(edge: .bottom) { //this will push the view when the keyboad is shown Color.clear.frame(height: 30) } }Puede proporcionar padding adicional a la vista (y funciona incluso en iOS 13 y 14):
struct ContentView: View { @State var text:String = "" var body: some View { ScrollView { VStack(spacing: 10) { ForEach(1...12, id: \.self) { Text("\($0)…") .frame(height:50) } TextField("Label..", text: self.$text) .padding(10) .background(.white) .cornerRadius(10) .overlay( RoundedRectangle(cornerRadius: 10) .stroke(.blue, lineWidth: 1) ) .padding(.bottom, 32) //here, set as much pasding as you want } .padding() .background(.red) } } }