1.重載touchesBegin方法
重載UIVIewController中的touchesBegin方法,
然后在里面執行[self.view endEditing:YES];
這樣單擊UIViewController的任意地方,就可以收起鍵盤了。
2.添加TapGesture
添加UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapViewAction)];
[self.view addGestureRecognizer:tapGesture];
實現方法:
-(void)tapViewAction{
[self.view endEnditing:YES]; //這里也可以指定是誰注銷了第一響應
}
3.在獲得當前UIViewController比較困難的時候1
直接執行 [[UIapplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil];
4.在獲得當前UIViewController比較困難的時候2
直接執行 [[[UIApplication sharedApplication] keyWindow] endEditing:YES];
新聞熱點
疑難解答