5

so whenever My Keyboard toggles the Tabbar moves up with it like shown in the image. Is there a way to prevent this when the Keyboard is active? My version is iOS 14 and XCode 12 Thanks in advance!

/// Corretion: How can I modify any View in SwiftUI to prevent moving up when the Keyboard shows up?

struct SwiftUIView: View {
@State var text = ""
var body: some View {
        VStack{
        TextField("Text", text: $text)
            Text(">>Don't Move Me Up When Keyboard Is Active<<")
    }
}

}

Paul

simulator view when tabbar moves up when keyboard is active

Paul
  • 153
  • 7
  • Can you show us some code? – Luke Sep 21 '20 at 18:40
  • 1
    Welcome to Stack Overflow. Please take the [tour] and review [ask]. You need to show us **at least** the code you are executing that causes the tab bar to move. – DonMag Sep 21 '20 at 20:07
  • hey, sorry, its a bit tricky as i implemented the code and there is a lot going on but as of the restrictions of the swiftui TabView I used a UITabbarcontroller wrapped in a Representable and then disabled the real TabBar to implement my own one which works. But as it is a custom one (A HStack with the icons in it) it is of course not recognized as a Tabbar. so the question is rather how can I prevent something in general from moving up when the keyboard shows up. Sorry for the bad description before... – Paul Sep 25 '20 at 15:38

1 Answers1

13

try adding the following modifier to your tabbar:

.ignoresSafeArea(.keyboard, edges: .bottom)

onejuan
  • 380
  • 2
  • 7
  • Hey, this works perfectly. I also found this one here where they mention to also add a Spacer() to make it work! Thank you so much! https://stackoverflow.com/questions/63968241/swiftui-in-ios14-keyboard-avoidance-issues-and-ignoressafearea-modifier-issues – Paul Sep 25 '20 at 16:12
  • @Paul would you mind marking this answer as accepted please? Glad it helped. – onejuan Oct 06 '20 at 12:19
  • 1
    I am using custom tab view and the solution is working when I add this modifier inside the navigation view – Shunan Feb 17 '22 at 04:27