Hide shortcut keyboard bar for UIWebView in iOS 9

让人想犯罪 __ 提交于 2019-12-03 03:21:13

Using method swiziling we can remove the keyboard shortcut bar (only works with ObjC).

 - (void)hideKeyboardShortcutBar
    {
        Class webBrowserClass = NSClassFromString(@"UIWebBrowserView");
        Method method = class_getInstanceMethod(webBrowserClass, @selector(inputAccessoryView));

        IMP newImp = imp_implementationWithBlock(^(id _s) {
            if ([self.webView respondsToSelector:@selector(inputAssistantItem)]) {
                UITextInputAssistantItem *inputAssistantItem = [self.webView inputAssistantItem];
                inputAssistantItem.leadingBarButtonGroups = @[];
                inputAssistantItem.trailingBarButtonGroups = @[];
            }
            return nil;
        });

        method_setImplementation(method, newImp);
    }

inputAccessoryView : This property is typically used to attach an accessory view to the system-supplied keyboard that is presented for UITextField and UITextView objects.

So the new implementation block will be fired every time the keyboard pops up.

UPDATE

To remove the accessory view from WKWebView use WKContentView instead of UIWebBrowserView

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