- 点击键盘的return键收回键盘
//需要实现UITextFieldDelegate协议中的方法
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
- 点击屏幕空白处收回键盘
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
[self.view endEditing:YES];
}
手势现实
- (void)viewDidLoad
{
self.view.userInteractionEnabled = YES;
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(fingerTapped:)];
[self.view addGestureRecognizer:singleTap];
}
- (void)fingerTapped:(UITapGestureRecognizer *)gestureRecognizer
{
[self.view endEditing:YES];
}
- 拖拽收回键盘
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
[self.view endEditing:YES];
}
网友评论