【iOS Swift 笔记1】退出键盘

2017-05-06  本文已影响0人  卖鱼家的少爷

项目里面很多东西要删掉了
所以在这里记一些笔记

    // 退出键盘-点击其他地方1
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        view.endEditing(true)
    }
    // 退出键盘-点击其他地方2
    override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
        [YourTextField].resignFirstResponder()
     }
    // 退出键盘-点击return键 [UITextFieldDelegate]
    func textFieldShouldReturn(_ textField: UITextField) -> Bool {
        textField.resignFirstResponder()
        return true
    }
上一篇 下一篇

猜你喜欢

热点阅读