Skip to content

Instantly share code, notes, and snippets.

@nurtugan
Created March 29, 2020 18:55
Show Gist options
  • Save nurtugan/6712c935a8b3ae9e77f0460a9c804bde to your computer and use it in GitHub Desktop.
Save nurtugan/6712c935a8b3ae9e77f0460a9c804bde to your computer and use it in GitHub Desktop.
Dismiss Keyboard by touching anywhere
extension UIViewController {
func hideKeyboardWhenTappedAround() {
let tap = UITapGestureRecognizer(
target: self,
action: #selector(dismissKeyboard)
)
tap.cancelsTouchesInView = false
view.addGestureRecognizer(tap)
}
@objc
func dismissKeyboard() {
view.endEditing(true)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment