收起键盘的2种方法

1:

[[[UIApplication sharedApplication] keyWindow] endEditing:YES];

2:

[[self findFirstResponderBeneathView:self] resignFirstResponder];

- (UIView*)findFirstResponderBeneathView:(UIView*)view

{

    // Search recursively for first responder

    for ( UIView *childView in view.subviews ) {

        if ( [childView respondsToSelector:@selector(isFirstResponder)] && [childView isFirstResponder] )

            return childView;

        UIView *result = [self findFirstResponderBeneathView:childView];

        if ( result )

            return result;

    }

    return nil;

}


你可能感兴趣的:(收起键盘的2种方法)