0

It is not question about how to keep TextField above keyboard (put it inside ScrollView), I wonder how to keep TextField containing View fully be visible above Keyboard. For example behind TextField some info text, which should be visible while user print the text.

VStack {  // This all should be above keyboard
    TextField(...)
    Text("Some hints about entered text")
}

In screens: Now I have this (you can see TextField just above keyboard, but we don't see content under TextField) enter image description here

But I want to get this (With "Some additional info" label, which should also pop above keyboard when TextField become first responder):

enter image description here

Konstantin.Efimenko
  • 1,242
  • 1
  • 14
  • 38
  • 1
    I think some screenshot from the internet would be very helpful to understand your question. – stackich Oct 19 '22 at 09:24
  • Added screens with more explanation – Konstantin.Efimenko Oct 24 '22 at 12:29
  • ok, so it has nothing to do with UITextField, it is more about putting ANY UI element above keyboard - so you can try this extension for SwiftUI, it was very easy to find, check comment below: – stackich Oct 24 '22 at 12:33
  • Does this answer your question? [Move TextField up when the keyboard has appeared in SwiftUI](https://stackoverflow.com/questions/56491881/move-textfield-up-when-the-keyboard-has-appeared-in-swiftui) – stackich Oct 24 '22 at 12:33
  • There are 20+ answers for different question, the latest one oldest than 2 years. I've tried couple, but they solve another problem. Which of them do you think I have to try? – Konstantin.Efimenko Oct 24 '22 at 13:31
  • the one with highest number of upvotes looks fine for me – stackich Oct 24 '22 at 13:33

2 Answers2

0

I was try you code and all warks fine right now but you can try like this:

VStack(alignment: .leading) { 
    TextField(...)
    Text("Some hints about entered text")
}
Maxim Zakopaylov
  • 546
  • 2
  • 5
  • 23
0

enter image description here

I don't know what I want because there's not much information I can get from the question, but is this right? I understand that you want to include a view that can be a hint from the view behind the TextField.

import SwiftUI

struct ContentView: View {
    @State private var text = ""
    
    var body: some View {
        VStack {  // This all should be above keyboard
            Spacer()
            TextField("", text: $text)
                .background {
                    Text("Some hints about entered text")
                        .foregroundColor(.gray)
                }
        }
        .padding()
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
monglong
  • 455
  • 3
  • 11