美文网首页
WKWebView实现UIWebView的keyboardDis

WKWebView实现UIWebView的keyboardDis

作者: MichalWilson | 来源:发表于2018-05-11 11:27 被阅读50次

    之前的解决方法在IOS 11.3之后就不好用了,必须区分开:

    实现webview显示自动弹出键盘功能

    + (void)allowDisplayingKeyboardWithoutUserAction {

        Class class = NSClassFromString(@"WKContentView");

        NSOperatingSystemVersion iOS_11_3_0 = (NSOperatingSystemVersion){11, 3, 0};

        if ([[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion: iOS_11_3_0]) {

            SEL selector = sel_getUid("_startAssistingNode:userIsInteracting:blurPreviousNode:changingActivityState:userObject:");

            Method method = class_getInstanceMethod(class, selector);

            IMP original = method_getImplementation(method);

            IMP override = imp_implementationWithBlock(^void(id me, void* arg0, BOOL arg1, BOOL arg2, BOOL arg3, id arg4) {

                ((void (*)(id, SEL, void*, BOOL, BOOL, BOOL, id))original)(me, selector, arg0, TRUE, arg2, arg3, arg4);

            });

            method_setImplementation(method, override);

        } else {

            SEL selector = sel_getUid("_startAssistingNode:userIsInteracting:blurPreviousNode:userObject:");

            Method method = class_getInstanceMethod(class, selector);

            IMP original = method_getImplementation(method);

            IMP override = imp_implementationWithBlock(^void(id me, void* arg0, BOOL arg1, BOOL arg2, id arg3) {

                ((void (*)(id, SEL, void*, BOOL, BOOL, id))original)(me, selector, arg0, TRUE, arg2, arg3);

            });

            method_setImplementation(method, override);

        }

    }

    相关文章

      网友评论

          本文标题:WKWebView实现UIWebView的keyboardDis

          本文链接:https://www.haomeiwen.com/subject/xdcfdftx.html