带有 iPhone OS 4 的 UI 键盘

发布于 2024-09-16 20:44:38 字数 213 浏览 8 评论 0原文

您好,我在 iPhone 4.0 操作系统上遇到了一个大问题,这段代码

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

在 UIKeyboard 无法工作的情况下。我尝试“UILayoutContainerView” 但它也不起作用。

请。

Hi I have a big problem with iPhone 4.0 OS with this code

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

in condition UIKeyboard it not working. I try "UILayoutContainerView"
but it not working too.

please.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

弃爱 2024-09-23 20:44:38

您可以尝试以下代码:

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

You can try this code:

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

And you also need to add this code to function didFinishLaunchingWithOptions in AppDelegate:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
浅黛梨妆こ 2024-09-23 20:44:38
@"<UIPeripheralHostView" will work instead of @"<UIKeyboard"

不知道为什么。

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

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

Dunno why.

Can you tell me then: How to determine the keyboard type in the UIKeyboard class?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文