美文网首页iOS开发
IOS WKWebView 键盘工具栏消除

IOS WKWebView 键盘工具栏消除

作者: 大大大_大哥哥 | 来源:发表于2016-08-16 13:45 被阅读3186次

消除下图中键盘工具栏

先创建一个类

NoInputAccessoryView.h

#import <Foundation/Foundation.h>

#import <WebKit/WebKit.h>

#import <objc/runtime.h>

@interface NoInputAccessoryView : NSObject

- (void)removeInputAccessoryViewFromWKWebView:(WKWebView *)webView;

@end

NoInputAccessoryView.m

#import "NoInputAccessoryView.h"

@implementation NoInputAccessoryView

- (id)inputAccessoryView {

return nil;

}

- (void)removeInputAccessoryViewFromWKWebView:(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([C3NoInputAccessoryView class], @selector(inputAccessoryView));

class_addMethod(newClass, @selector(inputAccessoryView), method_getImplementation(method), method_getTypeEncoding(method));

objc_registerClassPair(newClass);

}

object_setClass(targetView, newClass);

}

@end

类创建好之后再调用一下removeInputAccessoryViewFromWKWebView方法。传入WKWebView就好了。

相关文章

网友评论

    本文标题:IOS WKWebView 键盘工具栏消除

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