首先窜护,引用UITextFieldDelegate類
override func viewDidLoad() {
super.viewDidLoad()
text.delegate = self
}
//點(diǎn)擊return 收回鍵盤
func textFieldShouldReturn(textField: UITextField) -> Bool {
textField.resignFirstResponder()
return true
}
//點(diǎn)擊其他地方 收回鍵盤
override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
text.resignFirstResponder()
}