//tableview滚动时关闭键盘
_tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
//重载触摸方法,点击其他位置关闭键盘,由于有tableview(scrollview),暂时无效,需要写到viewdiddrag里面
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
[super touchesBegan:touches withEvent:event];
[self.view endEditing:YES];
}
//拿到textfield,移除第一响应者
[_textField resignFirstResponder]
//调用系统通知关闭
[[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil];
[[[UIApplication sharedApplication] keyWindow] endEditing:YES];
网友评论