在WKWebView中隐藏键盘附件栏 [英] Hiding Keyboard accessorybar in WKWebView

查看:442
本文介绍了在WKWebView中隐藏键盘附件栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在WKWebview中隐藏键盘附件栏?虽然UIWebView有一些资源,但我还是找不到Stackoverflow上的WkWebview。

How can I hide keyboard accessory bar in WKWebview? Although there are some resources for UIWebView, I haven't been able to find one for WkWebview on Stackoverflow.

相关:


  1. 删除附件项目UIWebView键盘

  2. iOS 7 UIWebView键盘问题

  1. Removing the accesory item on the UIWebView keyboard
  2. iOS 7 UIWebView keyboard issue


推荐答案

这可以在 WKWebView中实现使用该方法的变体在 UIWebView 上调出 inputAccessoryView

This is possible in WKWebView with a variant of the method for swizzling out the inputAccessoryView on UIWebView.

首先,添加这个小类:

@interface _NoInputAccessoryView : NSObject

@end

@implementation _NoInputAccessoryView

- (id)inputAccessoryView {
    return nil;
}

@end

接下来,添加此方法:

Next, add this method:

- (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([_NoInputAccessoryView class], @selector(inputAccessoryView));

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

        objc_registerClassPair(newClass);
    }

    object_setClass(targetView, newClass);
}

然后,您只需调用该方法并传入 WKWebView

Then all you have to do is call that method and pass in your WKWebView:

[self removeInputAccessoryViewFromWKWebView:webView];

注意:我还不确定这是否会通过应用审核,但它是非常类似于我用于 UIWebView 的相同代码,并确实通过了审核。

Note: I do not yet know for sure if this will pass app review, but it is extremely similar to the same code I used for UIWebView, and that did pass review.

更新:此代码位于已通过App Store审核的应用中。

Update: This code is in an app that has passed App Store review.

这篇关于在WKWebView中隐藏键盘附件栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆