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)
}
}
Related Topics
Swift Firestore Check If Documents Exists
Selectively Remove and Delete Objects from a Nsmutablearray in Swift
Swift Repl: How to Save/Load the Repl State? (A.K.A. Suspend/Resume, Snapshot, Clone)
Swift - Getting Only Alphanumeric Characters from String
Swift Language Statically or Dynamically Dispatched
Generic Method Override Not Working in Swift
Swift: Nstextfield Allow Only Specified Characters
How to Increase the Scope of Variables in Switch-Case/Loops in Swift
Textfield in Swiftui Loses Focus When I Enter a Character
How to Use Nsvisualeffectview to Blend Window with Background
Zposition of Sknode Relative to Its Parent
Swift- How to Display Image Over Button
Applewatch Messages Url Works Hard Coded But Not with Variables
Making Sklabelnode as a Crop Node of Skshapenode
Dynamically Call a Function in Swift