Skip to content

Instantly share code, notes, and snippets.

@ayoub-9
Last active December 13, 2018 16:56
Show Gist options
  • Select an option

  • Save ayoub-9/652f1eb85db4e90d6e94b44607887a02 to your computer and use it in GitHub Desktop.

Select an option

Save ayoub-9/652f1eb85db4e90d6e94b44607887a02 to your computer and use it in GitHub Desktop.
extension UIViewController {
func hideKeyboardWhenTappedAround() {
let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(UIViewController.dismissKeyboard))
tap.cancelsTouchesInView = false
view.addGestureRecognizer(tap)
}
func dismissKeyboard() {
view.endEditing(true)
}
}
-----
call him in ViewDidLoad
self.hideKeyboardWhenTappedAround()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment