第一种: 使用view的touchesBegan:触摸事件来实现对键盘的隐藏,当点击view的区域就会触发这个事件
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ [textFiled resignFirstResponder]; }
- (void)viewDidLoad { [super viewDidLoad]; UITap *tap = [[UITap alloc] initWithTarget:self action:@selector(keyboardHide:)]; //设置成NO表示当前控件响应后会传播到其他控件上,默认为YES。 tap.cancelsTouchesInView = NO; //将触摸事件添加到当前view [self.view addGestureRecognizer:tapGestureRecognizer]; } -(void)keyboardHide:(UITap*)tap{ [textFiled resignFirstResponder]; }
3、编写隐藏代码:
- (IBAction)touchView:(id)sender { [self.view endEditing:YES]; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/u012989536/article/details/48036021