【问题标题】:How to hide shortcut bar in iOS9 UIWebview?如何在 iOS9 UIWebview 中隐藏快捷栏?
【发布时间】:2015-09-24 20:14:17
【问题描述】:

当用户单击 UIWebView 中的文本字段时,我想隐藏键盘顶部的栏(撤消、重做、复制和返回、前进按钮)。

有人知道怎么做吗?

谢谢!

【问题讨论】:

  • 放入css文件:* { -webkit-touch-callout: none; -webkit 用户选择:无; /* 在 UIWebView 中禁用选择/复制 */ }
  • 谢谢,但我想隐藏那个栏。
  • 看起来与我的答案重复 stackoverflow.com/questions/32743649/…

标签: uiwebview ios9


【解决方案1】:

使用方法 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 :此属性通常用于将附件视图附加到 为 UITextField 提供的系统提供的键盘和 UITextView 对象。

所以每次键盘弹出时都会触发新的实现块。

我也在Hide shortcut keyboard bar for UIWebView in iOS 9 中发布了这个答案

【讨论】:

    【解决方案2】:

    我可以使用这些行隐藏那些

            let item:UITextInputAssistantItem = self.textFieldName.inputAssistantItem
            item.leadingBarButtonGroups = []
            item.trailingBarButtonGroups = []
    

    希望这会有所帮助。

    【讨论】:

    • 我没有文本字段。这是一个 Webview ;-)
    猜你喜欢
    • 2015-12-12
    • 2015-12-21
    • 1970-01-01
    • 2021-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多