Last active
December 19, 2017 22:22
-
-
Save jazzedge/3ae00d7322c28559f92801bb552a6511 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
See: https://freakycoder.com/ios-notes-31-how-to-hide-keyboard-by-touching-anywhere-cdf4f0c5151c | |
01. Create an extension | |
import UIKit | |
extension UIViewController { | |
func hideKeyboardWhenTappedAround() { | |
let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(UIViewController.dismissKeyboard)) | |
tap.cancelsTouchesInView = false | |
view.addGestureRecognizer(tap) | |
} | |
@objc func dismissKeyboard() { | |
view.endEditing(true) | |
} | |
} | |
02. Add this to viewDidLoad | |
// Hide Keyboard after tap is done | |
self.hideKeyboardWhenTappedAround() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment