Dismiss Keyboard with Swipe Gesture

Dismiss keyboard with swipe gesture

Since iOS 7, you can use

scrollView.keyboardDismissMode = .Interactive

From the documentation:

UIScrollViewKeyboardDismissModeInteractive

The keyboard follows the
dragging touch offscreen, and can be pulled upward again to cancel the
dismiss.

How to dismiss keyboard on swipe like in WhatsApp in SwiftUI

UIScrollView has keyboardDismissMode which when set to interactive, will achieve what you want. SwiftUI doesn’t provide direct support for this, but since under the hood, SwiftUI is using UIScrollView, you can use this which sets keyboardDismissMode to interactive for all scroll views in your app.

UIScrollView.appearance().keyboardDismissMode = .interactive

You must have a ScrollView in your view hierarchy for this to work. Here’s is a simple view demonstrating the behavior:

struct ContentView: View {
@State private var text = "Hello, world!"

var body: some View {
ScrollView {
TextField("Hello", text: $text)
.padding()
}
.onAppear {
UIScrollView.appearance().keyboardDismissMode = .interactive
}
}
}

The only caveat is that this affects all scroll views in your app. I don’t know of a simple solution if you only want to affect one scroll view in your app.

Dismiss keyboard on swipe back gesture in Flutter app

You need to create a custom class extending NavigatorObserver, and pass an instance of it to the navigatorObservers property of your MaterialApp or CupertinoApp.

Within that custom class, you can override didStartUserGesture and didStopUserGesture, which will be called when the swipe gesture starts/ends. This should allow you to achieve the behavior you are looking for. Note that didStartUserGesture indicates the current route as well as the previous route, based on which you could add logic to determine whether the keyboard should be dismissed or not.

How can I pan down to dismiss keyboard?

ScrollView component has a property called keyboarddismissmode.

keyboardDismissMode


Determines whether the keyboard gets dismissed in response to a drag.

Cross platform

  • none (the default), drags do not dismiss the keyboard.
  • on-drag, the keyboard is dismissed when a drag begins.

iOS Only

  • interactive, the keyboard is dismissed interactively with the drag and moves in synchrony with the touch; dragging upwards cancels
    the dismissal. On android this is not supported and it will have the
    same behavior as 'none'.

I have never used this property but from the description and from this answer, I think this is what you are looking for.

Swipe gesture to hide keyboard inside UITextView

Okey, guys... It's embarrassing but to solve this problem all you need to do is to select one option form the drop menu in Attributes Inspectore and everything works like a charm!

Here it is:

Sample Image

Dismiss UITextField Keyboard With Swipe

The easiest solution is to use a scroll view. Just put a scroll view behind your entire interface and boom, you're all set. This architecture has too many advantages to be rejected blithely. Even if the scroll view does not scroll normally, the user can use it to scroll when the keyboard is present (so as to be able to see the whole interface). What's more, it scrolls to reveal the first responder automatically — plus it gives you the keyboardDismissMode.



Related Topics



Leave a reply



Submit