1.关闭键盘的方式有几种,比较好用的一种就是给当前view添加一个手势监听:
/**
* @author Jerry.Yao, 15-09-30 18:09:58
*
* 给当前view添加手势识别
*/
- (void)setKeyBoardListener
{
UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(screenClick)];
[self.view addGestureRecognizer:recognizer];
}
/**
* @author Jerry.Yao, 15-09-30 18:09:32
*
* 点击屏幕关闭键盘
*/
- (void)screenClick
{
[self.view endEditing:YES];
}
2. 还有一种就是touch事件关闭:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[self.view endEditing:YES];
}
个人总结下这两个方法的不同点:貌似第二个方法只能用在UITextField的直接父控件是self.view的这种情况,否则可以用第一种方法。