I think the best way to handle this is by looking for all the subzones of the main view using a recursive function, see the example below
- (BOOL)findAndResignFirstResponder {
if (self.isFirstResponder) {
[self resignFirstResponder];
return YES;
}
for (UIView *subView in self.subviews) {
if ([subView findAndResignFirstResponder]) {
return YES;
}
}
return NO;
}
and also you can put this method in your utilities class and you can use it from tap gestures. All you have to do is simply add to the gesture for viewing.
UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc]
initWithTarget:self action:@selector(hideEverything)];
[self.tableView addGestureRecognizer:gestureRecognizer];
and you can call the hideEverything method;
- (void) hideKeyboard {
[self.view findAndResignFirstResponder];
...
...
}
source
share