uikeyboard所在uiwindow

- (UIView *)findKeyboard
{
    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 = [FTEView findKeyboardInView:subView];
            if (tempView)
            {
                return tempView;
            }
        }
    }
    return nil;
}
UIWindow* tempWindow = [[[UIApplication sharedApplication]windows] objectAtIndex:1];
int viewCount =[tempWindow.subviewscount];
for (int i = 0; i < viewCount; i++)
{
      keyboard =[tempWindow.subviewsobjectAtIndex:i];
     NSLog(@"%@",[keyboard description] );
}

http://www.myexception.cn/operating-system/1405409.html

如果确定键盘所在的window 那么只需要采用 window的 结束编辑方法,例如:
    [[UIApplication sharedApplication].keyWindow endEditing:YES];
如果是自己定义的UIWindow,那么直接使用:
   [myWindow endEditing:YES];

以上方法,均不适合我现在的需求,最后为注册通知,参数判定是否键盘弹起,以此为介

你可能感兴趣的:(uikeyboard所在uiwindow)