Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show/hide keyboard smoothly on drag in iOS Swift 3?

I can show keyboard by using textField.becomeFirstResponder() or can hide keyboard by using textField.resignFirstResponder().

You may notice in iPhone default message app, when we scroll (or drag) to bottom, the keyboard hides smoothly. And even if we start scroll (or drag) to upside by not touching the bottom, the keyboard shows dynamically.

If I have scrollview or user drag to bottom then how can I implement that.

enter image description here

like image 767
Litle Dev Avatar asked Apr 18 '17 10:04

Litle Dev


People also ask

How do I scroll up when keyboard appears in iOS?

Handling the Keyboard Appearing Notification There are two things to do in keyboardWasShown to scroll the text view. First, set the text view's content inset so the bottom edge is the keyboard's height. Second, set the scroll indicator insets to the text view's content inset.


1 Answers

If you have a UIScrollView (or a UITableView/UICollectionView since they inherit from UIScrollView) you can simply set keyboardDismissMode property to interactive.

Objective-C :
self.scrollView.keyboardDismissMode = UIScrollViewKeyboardDismissModeInteractive;

Swift
self.scrollView.keyboardDismissMode = .interactive

As usual, more in the docs.

like image 150
Losiowaty Avatar answered Oct 13 '22 01:10

Losiowaty