首先,引用UITextFieldDelegate类
override func viewDidLoad() {
super.viewDidLoad()
text.delegate = self
}
//点击return 收回键盘
func textFieldShouldReturn(textField: UITextField) -> Bool {
textField.resignFirstResponder()
return true
}
//点击其他地方 收回键盘
override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
text.resignFirstResponder()
}