美文网首页
ios 让WKWebview弹出键盘上的按钮影藏

ios 让WKWebview弹出键盘上的按钮影藏

作者: 管你爱不爱 | 来源:发表于2017-03-11 10:50 被阅读1032次
    #import
    
    @interface WKWebView (AccessoryHiding)
    
    @property (nonatomic, assign) BOOL hackishlyHidesInputAccessoryView;
    
    @end
    
    #import "WKWebView+AccessoryHiding.h"
    
    #import
    
    #import
    
    @implementation WKWebView (HackishAccessoryHiding)
    
    static const char * const hackishFixClassName = "WKContentViewMinusAccessoryView";
    
    static Class hackishFixClass = Nil;
    
    - (UIView *)hackishlyFoundBrowserView {
    
    UIScrollView *scrollView = self.scrollView;
    
    UIView *browserView = nil;
    
    for (UIView *subview in scrollView.subviews) {
    
    NSLog(@"%@",NSStringFromClass([subview class]));
    
    if ([NSStringFromClass([subview class]) hasPrefix:@"WKContentView"]) {
    
    browserView = subview;
    
    break;
    
    }
    
    }
    
    return browserView;
    
    }
    
    - (id)methodReturningNil {
    
    return nil;
    
    }
    
    - (void)ensureHackishSubclassExistsOfBrowserViewClass:(Class)browserViewClass {
    
    if (!hackishFixClass) {
    
    Class newClass = objc_allocateClassPair(browserViewClass, hackishFixClassName, 0);
    
    IMP nilImp = [self methodForSelector:@selector(methodReturningNil)];
    
    class_addMethod(newClass, @selector(inputAccessoryView), nilImp, "@@:");
    
    objc_registerClassPair(newClass);
    
    hackishFixClass = newClass;
    
    }
    
    }
    
    - (BOOL) hackishlyHidesInputAccessoryView {
    
    UIView *browserView = [self hackishlyFoundBrowserView];
    
    return [browserView class] == hackishFixClass;
    
    }
    
    - (void) setHackishlyHidesInputAccessoryView:(BOOL)value {
    
    UIView *browserView = [self hackishlyFoundBrowserView];
    
    if (browserView == nil) {
    
    return;
    
    }
    
    [self ensureHackishSubclassExistsOfBrowserViewClass:[browserView class]];
    
    if (value) {
    
    object_setClass(browserView, hackishFixClass);
    
    }
    
    else {
    
    Class normalClass = objc_getClass("WKContentView");
    
    object_setClass(browserView, normalClass);
    
    }
    
    [browserView reloadInputViews];
    
    }
    
    @end
    

    相关文章

      网友评论

          本文标题:ios 让WKWebview弹出键盘上的按钮影藏

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