Created
March 29, 2020 18:55
-
-
Save nurtugan/6712c935a8b3ae9e77f0460a9c804bde to your computer and use it in GitHub Desktop.
Dismiss Keyboard by touching anywhere
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
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