iOS回收键盘

1.回收某个textField下弹出的键盘

1 - (BOOL)textFieldShouldReturn:(UITextField *)textField{
2 
3     [textField resignFirstResponder];
4     return YES;
5 
6 }

2.点击空白处回收键盘

 1 -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
 2 
 3 {
 4 
 5     [self.phoneNumTF resignFirstResponder];
 6 
 7     [self.secretTF resignFirstResponder];
 8 
 9 
10 }

3.点击空白处回收键盘(添加手势)

 1 - (void)viewDidLoad  
 2 {  
 3     [super viewDidLoad];  
 4     UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(keyboardHide:)];  
 5     //设置成NO表示当前控件响应后会传播到其他控件上,默认为YES。  
 6     tapGestureRecognizer.cancelsTouchesInView = NO;  
 7     //将触摸事件添加到当前view  
 8     [self.view addGestureRecognizer:tapGestureRecognizer];  
 9 }  
10   
11 -(void)keyboardHide:(UITapGestureRecognizer*)tap{  
12     [textFiled resignFirstResponder];  
13 } 

 

posted @ 2015-11-17 17:39  脉脉不得语  阅读(330)  评论(0编辑  收藏  举报