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)
本文介绍了如何在iOS应用中实现点击Return按钮收起键盘、背景视图收起键盘及统一收起键盘的方法,适用于iOS开发者。
3087

被折叠的 条评论
为什么被折叠?



