Skip to content →

iOS Swipe Keyboard to dismiss

In iOS 7, Apple added an option to UIScrollView which could allow you to dismiss the keyboard when dragged.

UIScrollViewKeyboardDismissMode

public enum UIScrollViewKeyboardDismissMode : Int {

    case none

    case onDrag // dismisses the keyboard when a drag begins

    case interactive // the keyboard follows the dragging touch off screen, and may be pulled upward again to cancel the dismiss
}

This is very easy to do. Just set the keyboardDismissMode property to .onDrag or interactive:

let tableView = UITableView(frame: .zero, style: .plain)
tableView.keyboardDismissMode = .interactive

You should set this on all tableviews that contain text fields.

For example code, see: https://github.com/dougdiego/iOSDemos

Published in iOS