Newbie Questions Newbie Questions - 6 months ago 42
iOS Question

Dismiss Keyboard On drag

I would like to dismiss the keyboard on swipe/drag after i search for results in my


I tried doing it through the
but it didn't help.

if i search and get many results i would like scroll down and then the keyboard will
and let me see my results better.If anyone can help that would be great, Thanks ahead !

Right now, When i have my results as seen in the picture the keyboard stays when i scroll down and its kind of annoying.

I am using Swift 2.3 and Xcode 8.1

enter image description here

Here is my searchController setup just in case :

// MARK : Search ! //

var searchController : UISearchController!

var resultsController = UITableViewController()

override func viewDidLoad() {

definesPresentationContext = true
self.resultsController.tableView.dataSource = self
self.resultsController.tableView.delegate = self
self.searchController = UISearchController(searchResultsController: self.resultsController)
self.tableView.tableHeaderView = self.searchController.searchBar
self.searchController.searchResultsUpdater = self
self.searchController.dimsBackgroundDuringPresentation = true
self.searchController.searchBar.barTintColor = UIColor.blackColor()
self.searchController.searchBar.placeholder = "חפש ברים"
self.searchController.hidesNavigationBarDuringPresentation = false
////// MARK: END Of Search //////

Edit:Works but has a tiny issue

The last result's Cell is being cut in half! :

enter image description here


Implement the scroll view delegate method (scrollViewWillBeginDragging). In this method resignFirstResponder your search bar. You can also look at this SO answer.

func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {