Advertisement
neatekFb

Hide keyboard when you tap around the textfield or textview

Nov 4th, 2016
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.46 KB | None | 0 0
  1. // Vladimir Zhelnov - neatek.pw - Web/iOS dev
  2. override func viewDidLoad() {
  3.     super.viewDidLoad()
  4.     self.hideKeyboardWhenTappedAround()
  5. }
  6. extension UIViewController {
  7.     func hideKeyboardWhenTappedAround() {
  8.         let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(UIViewController.dismissKeyboard))
  9.         view.addGestureRecognizer(tap)
  10.     }
  11.    
  12.     func dismissKeyboard() {
  13.         view.endEditing(true)
  14.     }
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement