swift 点击屏幕回收键盘

override func viewDidLoad() {

        super.viewDidLoad()

        self.hideKeyboardWhenTappedAround();

        // Do any additional setup after loading the view.

    }

func hideKeyboardWhenTappedAround() {
        let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(dismissKeyboard))
        tap.cancelsTouchesInView = false
        view.addGestureRecognizer(tap)
    }
   
    @objc func dismissKeyboard() {
        view.endEditing(true)
    }

你可能感兴趣的:(swift 点击屏幕回收键盘)