In Messages.app you can dismiss the keyboard down by scrolling the list view. To be clear, it isn\'t simply responding to a scrollViewDidScroll
event. The keyboard
Since iOS7, UIScrollView
and all classes that inherit from it (including UITableView
) have a keyboardDismissMode property. With Swift 5 and iOS 12, keyboardDismissMode
has the following declaration:
var keyboardDismissMode: UIScrollView.KeyboardDismissMode { get set }
The manner in which the keyboard is dismissed when a drag begins in the scroll view.
Note that UIScrollView.KeyboardDismissMode is an enum that has none
, interactive
and onDrag
cases.
keyboardDismissMode
programmaticallyThe code snippet below shows a possible implementation of keyboardDismissMode
:
override func viewDidLoad() {
super.viewDidLoad()
// Dismiss keyboard when scrolling the tableView
tableView.keyboardDismissMode = UIScrollView.KeyboardDismissMode.interactive
/* ... */
}
keyboardDismissMode
in storyboardAs an alternative to the programmatic approach above, you can set the keyboardDismissMode
value for your UIScrollView
/UITableView
in the storyboard.
UIScrollView
/ UITableView
instance,