- 點擊鍵盤的return鍵收回鍵盤
//需要實現(xiàn)UITextFieldDelegate協(xié)議中的方法
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
- 點擊屏幕空白處收回鍵盤
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
[self.view endEditing:YES];
}
手勢現(xiàn)實
- (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];
}