Swiftui - Why Does the Keyboard Pushes My View

SwiftUI - Why does the keyboard pushes my view?

  • By default SwiftUI view doesn't ignore safe-area .

when keyboard come up the area belongs to safe area. so that you can ignore it using .ignoresSafeArea(.keyboard, edges: .bottom)

VStack {
...
}.navigationBarTitle("Search")
.ignoresSafeArea(.keyboard, edges: .bottom) //<- here

SwiftUI - How to prevent keyboard in a sheet to push up my main UI

I had a similar problem once. I can't reproduce your code, but you might try using GeometryRadar like this:

    GeometryReader { geometry in
ZStack {
VStack {

// This is the part that moves up and down
}
}
}
.ignoresSafeArea(.keyboard, edges: .bottom)


SwiftUI : How I can push my view above to use textfield?(halfASheet, TextEditor)

You can change your value on height when you focused on textField

@State var isEditing = false

TextField("", text: $text, onEditingChanged: { edit in
self.isEditing = edit
})

HalfASheet(isPresented: $showAddSheet) {
halfSheetView
}
.height(.proportional(isEditing ? 0.25 : 0.75))

iOS 14 SwiftUI Keyboard lifts view automatically

You should apply the modifier on the ZStack, NOT the NavigationView

NavigationView(content: {
ZStack{
,,,
}.navigationBarHidden(true)
.navigationBarTitle("")
.ignoresSafeArea(.keyboard, edges: .bottom) // <- This line moved up
})


Full working example:

struct ContentView: View {
@State var text = ""
var body: some View {
VStack{
Spacer()
Text("Hello, World")
TextField("Tap to test keyboard ignoring", text: $text)
.textFieldStyle(RoundedBorderTextFieldStyle())
}
.padding()
.ignoresSafeArea(.keyboard, edges: .bottom)
}
}

Demo



Related Topics



Leave a reply



Submit