iOS点击非输入框时隐藏键盘详解手机开发

- (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

(0)
上一篇 2021年7月16日
下一篇 2021年7月16日

相关推荐

发表回复

登录后才能评论