Created
February 17, 2022 16:05
-
-
Save RealEmmettS/cdc4c84a678ca59359a026ff73881920 to your computer and use it in GitHub Desktop.
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
//Paste in an 'extra' (global) Swift file, or after the class in a viewController file | |
extension UIViewController { | |
func hideKeyboardWhenTappedAround() { | |
let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(UIViewController.dismissKeyboard)) | |
view.addGestureRecognizer(tap) | |
} | |
@objc func dismissKeyboard() { | |
view.endEditing(true) | |
} | |
} | |
//Paste in any viewController which presents a keyboard | |
self.hideKeyboardWhenTappedAround() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment