感觉IOS的键盘回收好累,所以封装了一个通用一点的方法
-(IBAction)spbResignFirstResponder:(id)sender { // NSLogObj(sender); if (sender == NULL || [sender isKindOfClass:[UITapGestureRecognizer class]]) { if (self.view != NULL && self.view.subviews != NULL && self.view.subviews.count > 0) { for (UIView *item in self.view.subviews) { if ([item isKindOfClass:[UITextField class]] || [item isKindOfClass:[UITextView class]]) { UITextField *textField_item = (UITextField *)item; [textField_item resignFirstResponder]; } [self spbResignFirstResponder:item]; } } }else if ([sender isKindOfClass:[UIView class]]) { UIView *view_item = sender; if ([view_item isKindOfClass:[UITextField class]] || [view_item isKindOfClass:[UITextView class]]) { [view_item resignFirstResponder]; } if (view_item.subviews != NULL && view_item.subviews.count > 0) { for (UIView *item in view_item.subviews) { [self spbResignFirstResponder:item]; } } } }
时间: 2024-11-05 20:48:50