1、点击Return按扭时收起键盘
func textFieldShouldReturn(textField: UITextField) -> Bool {
textField.resignFirstResponder()
return true
}
2、点击背景View收起键盘(你的View必须是继承于UIControl)
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
self.view.endEditing(true)
}
3、你可以在任何地方加上这句话,可以用来统一收起键盘
UIApplication.sharedApplication().keyWindow?.endEditing(true)