方法一:
通过
Return
键来触发
UITextField
的
Did End on Exit
事件来隐藏。
// sender 参数为当前的 UITextField
- (IBAction)TextField_DidEndOnExit:(id)sender {
// 隐藏键盘.
[sender resignFirstResponder];
}
也可以通过点击其他按钮或者其他方法来执行:
[_textField resignFirstResponder];
方法二:
点击空白的地方隐藏键盘,注意!点击的是 View 空白的地方才可以,点击其他控件不可以!
设置 View 的 Custom Class 的 Class 为 UIControl。
这样右击 View 就会出现 Touch Down 事件。
- (IBAction)View_TouchDown:(id)sender {
[[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil];
}