Last active
May 6, 2020 16:06
-
-
Save jimbrayrcp/55c902545a356a5c3c01b084a9431be1 to your computer and use it in GitHub Desktop.
Works in Swift 5: iOS: 13.1 Dismiss a keyboard when tapping outside of field
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ************************************ | |
// ADD TO VIEW DID LOAD | |
// ------------------------------------ | |
let tap: UITapGestureRecognizer = UITapGestureRecognizer( | |
target: self, | |
action: #selector(UIInputViewController.dismissKeyboard)) | |
//Uncomment to prevent interference of cancel button | |
//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