Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // ViewController.swift
- // MasjidLink
- //
- // Created by Sebastian Vidrea on 08/04/2019.
- // Copyright © 2019 Sebastian Vidrea. All rights reserved.
- //
- import UIKit
- extension UIViewController: UIGestureRecognizerDelegate {
- func hideKeyboardWhenTappedAround() {
- let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(dismissKeyboard))
- tap.cancelsTouchesInView = false
- tap.delegate = self
- view.addGestureRecognizer(tap)
- }
- @objc func dismissKeyboard() {
- view.endEditing(true)
- }
- public func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
- if touch.view is UIButton {
- return false
- }
- return true
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement