bb4
bb4

Reputation: 25

SwiftUI How to avoid keyboard with a ScrollView inside a VStack

I've seen a few threads on keyboard avoidance but none seem to address my exact situation.

My view is basically laid out like this:

VStack() {

            Picker("Which tab?", selection: $selectedSegment) {
                ForEach(tab.indices, id: \.self) { index in
                    Text(tab[index])
                }
            }.pickerStyle(.segmented)
         
            
            HeaderSubView()
            
            if selectedSegment == 0 {
                ScrollView(){

                      TextField("Text1", text: $text1)
                      \\Just left one textfield for simplicity

                }
                    
                    FooterSubview()

}

When I click the textfield to type the footer slides up on top of the keyboard, blocking the textfield from being seen. How do I keep the selected textfield focused in the view?

I've tried using .ignoreSafeAreas() and I attempted a geometryReader but it didn't work as expected either.

Upvotes: 0

Views: 660

Answers (0)

Related Questions