设为首页 加入收藏

TOP

ios 让WKWebview弹出键盘上的按钮影藏
2017-10-13 10:33:56 】 浏览:6278
Tags:ios WKWebview 键盘 按钮

#import <WebKit/WebKit.h>

@interface WKWebView (AccessoryHiding)

@property (nonatomic, assign) BOOL hackishlyHidesInputAccessoryView;


@end

 

 

#import "WKWebView+AccessoryHiding.h"

#import <objc/runtime.h>
#import <UIKit/UIKit.h>

@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中的单例模式 下一篇IOS客户端Coding项目记录导航

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

最新文章

热门文章

C 语言

C++基础

windows编程基础

linux编程基础

C/C++面试题目