iOS: How to access the `UIKeyboard`?

后端 未结 6 918
执念已碎
执念已碎 2020-12-06 07:31

I want to get a pointer reference to UIKeyboard *keyboard to the keyboard on screen so that I can add a transparent subview to it, covering it completely, to ac

6条回答
  •  暖寄归人
    2020-12-06 08:07

    Try this:

    // my func
    - (void) findKeyboard {
    
        // Locate non-UIWindow.
        UIWindow *keyboardWindow = nil;
        for (UIWindow *testWindow in [[UIApplication sharedApplication] windows]) {
            if (![[testWindow class] isEqual:[UIWindow class]]) {
               keyboardWindow = testWindow;
               break;
           }
        }
    
        // Locate UIKeyboard.  
        UIView *foundKeyboard = nil;
        for (UIView *possibleKeyboard in [keyboardWindow subviews]) {
    
            // iOS 4 sticks the UIKeyboard inside a UIPeripheralHostView.
            if ([[possibleKeyboard description] hasPrefix:@"

提交回复
热议问题