SHARE
TWEET

Untitled

a guest Jun 18th, 2019 44 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. //  ViewController.swift
  3. //  MasjidLink
  4. //
  5. //  Created by Sebastian Vidrea on 08/04/2019.
  6. //  Copyright © 2019 Sebastian Vidrea. All rights reserved.
  7. //
  8.  
  9. import UIKit
  10.  
  11. extension UIViewController: UIGestureRecognizerDelegate {
  12.    
  13.     func hideKeyboardWhenTappedAround() {
  14.         let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(dismissKeyboard))
  15.         tap.cancelsTouchesInView = false
  16.         tap.delegate = self
  17.         view.addGestureRecognizer(tap)
  18.     }
  19.    
  20.     @objc func dismissKeyboard() {
  21.         view.endEditing(true)
  22.     }
  23.    
  24.     public func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
  25.         if touch.view is UIButton {
  26.             return false
  27.         }
  28.         return true
  29.     }
  30.    
  31. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top