Last active
September 28, 2017 04:31
-
-
Save khawajafarooq/fd61b7cde117c3c32a7d2ef7f5578ac6 to your computer and use it in GitHub Desktop.
Hiding keyboard category on clicking anywhere on the screen
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
import Foundation | |
extension UIViewController { | |
func hideKeyboardWhenTappedAround() { | |
let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(UIViewController.dismissKeyboard)) | |
view.addGestureRecognizer(tap) | |
} | |
func dismissKeyboard(_ sender: UITapGestureRecognizer) { | |
self.view.endEditing(true) | |
} | |
} | |
// How to use it? | |
... | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
self.hideKeyboardWhenTappedAround() | |
} | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment