Last active
April 9, 2019 06:37
-
-
Save Zeta611/5ca491af89ed912b54ae1836716ad57b to your computer and use it in GitHub Desktop.
[UIViewController+hideKeyboardWhenTappedAround] #extension #iOS
This file contains 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
// | |
// UIViewController+hideKeyboardWhenTappedAround.swift | |
// | |
// Created by Jay Lee on 18/02/2019. | |
// Copyright © 2019 Jay Lee <jaeho.lee@snu.ac.kr> | |
// This work is free. You can redistribute it and/or modify it under the | |
// terms of the Do What The Fuck You Want To Public License, Version 2, | |
// as published by Sam Hocevar. See http://www.wtfpl.net/ for more details. | |
// | |
import UIKit | |
extension UIViewController { | |
func hideKeyboardWhenTappedAround() { | |
let tap = UITapGestureRecognizer(target: self, action: #selector(dismissKeyboard)) | |
tap.cancelsTouchesInView = false | |
view.addGestureRecognizer(tap) | |
} | |
@objc private func dismissKeyboard(_ sender: UITapGestureRecognizer) { | |
view.endEditing(true) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment