- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField { UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(done:)]; tapGestureRecognizer.numberOfTapsRequired = 1; [self.view addGestureRecognizer: tapGestureRecognizer]; //只需要点击非文字输入区域就会响应hideKeyBoard [tapGestureRecognizer release]; return YES; } -(void)done:(id)sender { for (UIView *view in self.view.subviews) { if ([view isKindOfClass:[UITextField class]]) { [view resignFirstResponder]; } } }
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/3318.html