iOS关闭键盘的两种简单方法

方法一:


    //1, 关闭键盘

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

 

 

方法二:

   //2, 关闭键盘



    [[self findFirstResponderBeneathView:selfresignFirstResponder];

 


- (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;

}


你可能感兴趣的:(ios键盘)