iOS 收起键盘的几种方式
1.一般的view上收起键盘
// 手势
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
[self.cellphone resignFirstResponder];
[self.password resignFirstResponder];
}
2.tableView 上收起键盘
// 通过滚动收起
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
[tf resignFirstResponder];
[self.name resignFirstResponder];
}
// 通过手势
- (void)viewDidLoad {
[super viewDidLoad];
UITapGestureRecognizer *tableViewGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(commentTableViewTouchInSide)];
tableViewGesture.numberOfTapsRequired = 1;
tableViewGesture.cancelsTouchesInView = NO;
[self.tableView addGestureRecognizer:tableViewGesture];
}
- (void)commentTableViewTouchInSide{
[tf resignFirstResponder];
[self.name resignFirstResponder];
}
时间: 2024-12-27 21:17:13