首先介紹一下通用方法
遵循UITextFieldDelegate的代理方法
- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent *)event{
[self.view endEditing:YES];
}
這個方法只能適用控件是放在view上面,才有效,當遇到UIScrollView、UITableView就不太好使了。
下面介紹一種萬能用法,使用手勢隱藏鍵盤
UITapGestureRecognizer *myTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(scrollTap:)];
[_myTableView addGestureRecognizer:myTap];
在手勢方法中隱藏鍵盤
- (void)scrollTap:(id)sender {
[self.view endEditing:YES];
}
###iOS技術交流群:668562416
#### 源碼Demo獲取方法
關注「網羅開發」公眾號 ,有iOS demo、RN 視頻以及demo、Android demo等你領取。
***

小專欄:https://xiaozhuanlan.com/u/fanbaoying