0

嗨,我对 iPhone 4.0 OS 的代码有一个大问题

if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES) {
}

在 UIKeyboard 条件下它不起作用。我尝试“UILayoutContainerView”,但它也不起作用。

请。

4

2 回答 2

0
@"<UIPeripheralHostView" will work instead of @"<UIKeyboard"

不知道为什么。

那你能告诉我:如何确定UIKeyboard类中的键盘类型?

于 2011-01-08T23:15:20.030 回答
0

你可以试试这段代码:

- (BOOL) findKeyboard:(UIView *) superView; 
{
    UIView *currentView;
    if ([superView.subviews count] > 0) {
        for(int i = 0; i < [superView.subviews count]; i++)
        {

            currentView = [superView.subviews objectAtIndex:i];
            NSLog(@"%@",[currentView description]);
            if([[currentView description] hasPrefix:@"<UIKeyboard"] == YES)
            {

                NSLog(@"Find it");

                return YES;
            }
            if ([self findKeyboard:currentView]) return YES;
        }
    }

    return NO;

}

-(void) checkKeyBoard {
    UIWindow* tempWindow;

    for(int c = 0; c < [[[UIApplication sharedApplication] windows] count]; c ++)
    {
        tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:c];
        if ([self findKeyboard:tempWindow])
            NSLog(@"Finally, I found it");  
    }
}

- (void)keyboardWillShow:(NSNotification *)note {
    [self performSelector:(@selector(checkKeyBoard)) withObject:nil afterDelay:0];
}

您还需要将此代码添加到 AppDelegate 中的 didFinishLaunchingWithOptions 函数中:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
于 2010-09-13T04:48:52.407 回答