Dismiss keyboard with swipe gesture

In the XCode, attributes inspector, the scrollView has a Keyboard attribute. It has 3 options.

  • Do not dismiss
  • Dismiss on drag
  • Dismiss interactive.

UIScrollView properties


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.


If you're using a tableView and Swift 3 or Swift 4, it works by using:

tableView.keyboardDismissMode = .onDrag