陈斌彬的技术博客

Stay foolish,stay hungry

iOS 关闭键盘 取消文本框第一响应

- (void)viewDidLoad  
{  
    [super viewDidLoad];  
    UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(keyboardHide:)];  
    //设置成NO表示当前控件响应后会传播到其他控件上,默认为YES。  
    tapGestureRecognizer.cancelsTouchesInView = NO;  
    //将触摸事件添加到当前view  
    [self.view addGestureRecognizer:tapGestureRecognizer];  
}  

-(void)keyboardHide:(UITapGestureRecognizer*)tap{  
    [textFiled resignFirstResponder];  
}  

Resource Reference