Hide the keyBoard when tapping on the View iOS Swift
If the user is started typing in the text field and if the user taps on the view then keyboard wants to be dismissed then as follows.
class ViewController: UIViewController, UIGestureRecognizerDelegate
{
}
extension ViewController {
func hideKeyboardWhenTappedAround() {
let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(ViewController.dismissKeyboard))
tap.cancelsTouchesInView = false
view.addGestureRecognizer(tap)
}
func dismissKeyboard() {
view.endEditing(true)
}
}
Comments
Post a Comment