码迷,mamicode.com
首页 > 移动开发 > 详细

iOS回收键盘

时间:2015-11-17 19:02:01      阅读:236      评论:0      收藏:0      [点我收藏+]

标签:

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 } 

 

iOS回收键盘

标签:

原文地址:http://www.cnblogs.com/zcl410/p/4972394.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!