美文网首页
iOS收起键盘的几种方式

iOS收起键盘的几种方式

作者: KKFantasy | 来源:发表于2016-05-22 14:12 被阅读0次
- (void)viewDidLoad {
    //点击textField之外收起键盘
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissKeyboard)];
    tap.cancelsTouchesInView = NO;//防止tap影响subView响应事件
    [self.view addGestureRecognizer:tap];
    
    //tableView滑动收起键盘
    [self.table.panGestureRecognizer addTarget:self action:@selector(dismissKeyboard)];
}
    
#pragma mark - 收起键盘
-(void)dismissKeyboard {
    [self.view endEditing:YES];
}

#pragma mark - UITextFieldDelegate
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    //点击键盘上的return收起键盘
    [textField resignFirstResponder];
    return YES;
}

相关文章

网友评论

      本文标题:iOS收起键盘的几种方式

      本文链接:https://www.haomeiwen.com/subject/xjworttx.html