Litle Dev
Litle Dev

Reputation: 493

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

Upvotes: 6

Views: 6068

Answers (3)

Let.Simoo
Let.Simoo

Reputation: 93

for any object inherit from UIScrollView you can either to set (Dismiss on drag) for Keyboard option from the Attributes inspector or to use below code for swift:

self.scrollView.keyboardDismissMode = .interactive

Upvotes: 0

YanSte
YanSte

Reputation: 10839

Easy way to dismiss keyboard when touch or drag

Upvotes: 1

Losiowaty
Losiowaty

Reputation: 8006

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.

Upvotes: 12

Related Questions