Can't move keyboard view iOS9 swift

前端 未结 1 1676
走了就别回头了
走了就别回头了 2021-01-19 17:37

I need to implement a dismissive keyboard (swiping down to dismiss) like the one in the stock messages app on iOS.

I have this code to get the keyboard view:

相关标签:
1条回答
  • 2021-01-19 18:23

    In iOS 9 there is a new window for keyboard named UIRemoteKeyboardWindow, so when you are using accessoryView.superview you will get a wrong view.

    To get correct view try to find it from window hierarchy directly: (objective-c code)

    -(UIView*)getKeyboardInputView {
        if([[UIDevice currentDevice].systemVersion floatValue] >= 9.0) {
            for(UIWindow* window in [[UIApplication sharedApplication] windows])
                if([window isKindOfClass:NSClassFromString(@"UIRemoteKeyboardWindow")])
                    for(UIView* subView in window.subviews)
                        if([subView isKindOfClass:NSClassFromString(@"UIInputSetHostView")])
                            for(UIView* subsubView in subView.subviews)
                                if([subsubView isKindOfClass:NSClassFromString(@"UIInputSetHostView")])
                                    return subsubView;
        } else {
            return accessoryView.superview;
        }
        return nil;
    }
    

    P.S. Taken from DAKeyboardControl https://github.com/danielamitay/DAKeyboardControl/pull/98

    0 讨论(0)
提交回复
热议问题