- 点击键盘retrun进行关闭
// 继承 UITextFieldDelegate
class LoginViewController: UIViewController,UITextFieldDelegate {
}
// 绑定
override func viewDidLoad() {
super.viewDidLoad()
passwordTF.delegate = self
}
// 实现 textFieldShouldReturn 方法
func textFieldShouldReturn(textField: UITextField) -> Bool {
passwordTF.resignFirstResponder()
return true
}
2. 点击其他地方进行关闭 touchesEnded
override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
passwordTF.resignFirstResponder()
}