问题描述
如何在 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.
相关:
- 删除 UIWebView 键盘上的配件
- iOS 7 UIWebView 键盘问题
推荐答案
这可以在 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 中隐藏键盘辅助栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)