我正在为iOS开发PhoneGap应用程序,我需要摆脱新的iOS 9快捷键.现在我在 – (void)viewDidLoad方法中执行以下操作
if ([self.webView respondsToSelector:@selector(inputAssistantItem)]) { UITextInputAssistantItem *inputAssistantItem = [self.webView inputAssistantItem]; inputAssistantItem.leadingBarButtonGroups = @[]; inputAssistantItem.trailingBarButtonGroups = @[]; }
这隐藏了撤消/重做和复制/粘贴按钮,但快捷栏仍然显示在键盘上并且上面有导航按钮.
我怎样才能完全摆脱快捷栏.
谢谢你的帮助!
***更新1 ***
我的完整工作代码如下.希望这可以帮到某人(感谢@Clement的回复)
#import <objc/runtime.h> - (void) hideKeyboardShortcutBar: (UIView *)view { for (UIView *sub in view.subviews) { [self hideKeyboardShortcutBar:sub]; if ([NsstringFromClass([sub class]) isEqualToString:@"UIWebbrowserView"]) { Method method = class_getInstanceMethod(sub.class,@selector(inputAccessoryView)); IMP newImp = imp_implementationWithBlock(^(id _s) { if ([sub respondsToSelector:@selector(inputAssistantItem)]) { UITextInputAssistantItem *inputAssistantItem = [sub inputAssistantItem]; inputAssistantItem.leadingBarButtonGroups = @[]; inputAssistantItem.trailingBarButtonGroups = @[]; } return nil; }); method_setImplementation(method,newImp); } } } - (void)viewDidLoad { [super viewDidLoad]; [self hideKeyboardShortcutBar:self.webView]; }
这个技巧将隐藏撤消/重做和导航按钮.但自动预测文本仍将显示在键盘上.要隐藏快捷方式栏,请将html属性添加到输入元素中
<input autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" />
P.S我的应用程序现在正在审核中.仍然不知道Apple是否会批准这一点.
***更新2 ***
我的应用程序已获Apple批准
解决方法
使用方法swiziling我们可以删除键盘快捷键(仅适用于ObjC).
- (void)hideKeyboardShortcutBar { Class webbrowserClass = NSClassFromString(@"UIWebbrowserView"); Method method = class_getInstanceMethod(webbrowserClass,@selector(inputAccessoryView)); IMP newImp = imp_implementationWithBlock(^(id _s) { if ([self.webView respondsToSelector:@selector(inputAssistantItem)]) { UITextInputAssistantItem *inputAssistantItem = [self.webView inputAssistantItem]; inputAssistantItem.leadingBarButtonGroups = @[]; inputAssistantItem.trailingBarButtonGroups = @[]; } return nil; }); method_setImplementation(method,newImp); }
inputAccessoryView
: This property is typically used to attach an accessory view to the
system-supplied keyboard that is presented for UITextField and
UITextView objects.
因此,每次键盘弹出时都会触发新的实现块.
UPDATE
要从WKWebView中删除附件视图,请使用WKContentView而不是UIWebbrowserView