Can't move keyboard view iOS9 swift

≡放荡痞女 提交于 2019-12-01 20:51:09

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!