By default, iOS opens web pages using a Webview and pops up a toolbar at the top of the keyboard when typing forms.
There are two up and down buttons on the left and a Done/ Done button on the right. This is used to switch input fields, just as you can switch input fields on a PC by pressing the Tab key.
In order to make the H5 embedded in the App closer to Native, we can remove it.
UIWebView
UIWebView, can use [self hideKeyboardShortcutBar: self. WebView] get rid of the toolbar.
- (void) hideKeyboardShortcutBar: (UIView *)view { for (UIView *sub in view.subviews) { [self hideKeyboardShortcutBar:sub]; if ([NSStringFromClass([sub class]) isEqualToString:@"UIWebBrowserView"]) { Method method = class_getInstanceMethod(sub.class, @selector(inputAccessoryView)); IMP newImp = imp_implementationWithBlock(^(id _s) { if ([sub respondsToSelector:@selector(inputAssistantItem)]) { UITextInputAssistantItem *inputAssistantItem = [sub inputAssistantItem]; inputAssistantItem.leadingBarButtonGroups = @[]; inputAssistantItem.trailingBarButtonGroups = @[]; } return nil; }); method_setImplementation(method, newImp); }}}Copy the code
WkWebView
WkWebView, can use [self hideWKWebviewKeyboardShortcutBar: self. WebView] get rid of the toolbar.
// Create a _noinputAccessoryView@interface _NoInputAccessoryView: NSObject @end @implementation _NoInputAccessoryView - (id)inputAccessoryView { return nil; } @end // Step 2: Remove WkWebviewe Done toolbar - (void) hideWKWebviewKeyboardShortcutBar: (WKWebView *) webView {UIView * targetView; for (UIView *view in webView.scrollView.subviews) { if([[view.class description] hasPrefix:@"WKContent"]) { targetView = view; } } if (! targetView) { return; } NSString *noInputAccessoryViewClassName = [NSString stringWithFormat:@"%@_NoInputAccessoryView", targetView.class.superclass]; Class newClass = NSClassFromString(noInputAccessoryViewClassName); if(newClass == nil) { newClass = objc_allocateClassPair(targetView.class, [noInputAccessoryViewClassName cStringUsingEncoding:NSASCIIStringEncoding], 0); if(! newClass) { return; } Method method = class_getInstanceMethod([_NoInputAccessoryView class], @selector(inputAccessoryView)); class_addMethod(newClass, @selector(inputAccessoryView), method_getImplementation(method), method_getTypeEncoding(method)); objc_registerClassPair(newClass); } object_setClass(targetView, newClass); }Copy the code