ios捕捉键盘view

- (UIView *)getKeyboardView

{

    UIView *keyboardView = nil;

    NSArray *windows = [[UIApplication sharedApplication] windows];

    for (UIWindow *window in [windows reverseObjectEnumerator])//逆序效率更高,因为键盘总在上方

    {

        keyboardView = [self findKeyboardInView:window];

        if (keyboardView)

        {

            return keyboardView;

        }

    }

    return nil;

}

- (UIView *)findKeyboardInView:(UIView *)view

{

    for (UIView *subView in [view subviews])

    {

        if (strstr(object_getClassName(subView), "UIKeyboard"))

        {

            return subView;

        }

        else

        {

            UIView *tempView = [self findKeyboardInView:subView];

            if (tempView)

            {

                return tempView;

            }

        }

    }

    return nil;

}

 

posted on 2016-10-31 10:38  WW稳  阅读(127)  评论(0编辑  收藏  举报