iOS: How to access the `UIKeyboard`?

后端 未结 6 906
执念已碎
执念已碎 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 07:48

    I found that developerdoug's answer wasn't working on iOS 7, but by modifying things slightly I managed to get access to what I needed. Here's the code I used:

    -(UIView*)findKeyboard
    {
        UIView *keyboard = nil;
    
        for (UIWindow* window in [UIApplication sharedApplication].windows)
        {
            for (UIView *possibleKeyboard in window.subviews)
            {
                if ([[possibleKeyboard description] hasPrefix:@"

    From what I could make out, in iOS 7 the keyboard is composed of a UIPeripheralHostView containing two subviews: a UIKBInputBackdropView (which provides the blur effect on whatever's underneath the keyboard) and a UIKeyboardAutomatic (which provides the character keys). Manipulating the UIPeripheralHostView seems to be equivalent to manipulating the entire keyboard.

    Discaimer: I have no idea whether Apple will accept an app that uses this technique, nor whether it will still work in future SDKs.

提交回复
热议问题