Xcode 6 Swift WKWebView键盘设置 [英] Xcode 6 Swift WKWebView keyboard settings

查看:276
本文介绍了Xcode 6 Swift WKWebView键盘设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用WKWebView加载网站,并且一切正常.但是,我无法像使用文本字段一样访问键盘属性.有人可以向我指出一些资源,这些资源可以帮助我(通过GUI或以编程方式)访问网络上键盘的属性吗?

I'm using a WKWebView to load a website and everything is working fine. However, I do not have access to the keyboard properties the same way I do with a textfield. Can someone point me to some resources that will help me access properties (through the gui or programmatically) of the keyboard on the web?

推荐答案

The Text Programming Guide for iOS, has a section called Configuring the Keyboard for Web Views that states the following:

尽管UIWebView类不直接支持UITextInputTraits协议,但是您可以为文本输入元素配置一些键盘属性.例如,可以在输入元素的定义中包括autocorrectautocapitalize属性,以指定键盘的行为,如以下示例所示.

Although the UIWebView class does not support the UITextInputTraits protocol directly, you can configure some keyboard attributes for text input elements. For example, you can include autocorrect and autocapitalize attributes in the definition of an input element to specify the keyboard’s behaviors, as shown in the following example.

<input type="text" size="30" autocorrect="off" autocapitalize="on">

您还可以控制当用户触摸网页中的文本字段时显示的键盘类型.要显示电话键盘,电子邮件键盘或URL键盘,请分别对输入元素上的type属性使用telemailurl关键字.为了显示数字键盘,将模式属性的值设置为"[0-9]*".或"\d*".

You can also control which type of keyboard is displayed when a user touches a text field in a web page. To display a telephone keypad, an email keyboard, or a URL keyboard, use the tel, email, or url keywords for the type attribute on an input element, respectively. To display a numeric keyboard, set the value of the pattern attribute to "[0-9]*" or "\d*".

这些关键字和pattern属性是HTML 5的一部分,可在iOS中使用.下面的列表显示了如何显示每种类型的键盘,包括标准键盘.

These keywords and the pattern attribute are part of HTML 5 and are available in iOS. The following list shows how to display each type of keyboard, including the standard keyboard.

文本:<input type="text"></input>
电话:<input type="tel"></input>
网址:<input type="url"></input>
电子邮件:<input type="email"></input>
邮政编码:<input type="text" pattern="[0-9]*"></input>

Text: <input type="text"></input>
Telephone: <input type="tel"></input>
URL: <input type="url"></input>
Email: <input type="email"></input>
Zip code: <input type="text" pattern="[0-9]*"></input>

当然,这只能在有限的情况下解决一些非常具体的问题,但据我所知,即使使用WKWebView,我们也要使用这些.

That, of course, only solves some very specific problems in a limited number of situations, but as far as I know that's all we've got to work with, even with WKWebView.

我希望有人能证明我错了,并让我们知道如何添加键盘附件视图,或者当键盘专注于iOS应用程序中Web视图内的表单元素时如何更改键盘的外观.

I would love for someone to prove me wrong and let us know how to add a keyboard accessory view, or change the appearance of the keyboard when it's focused on a form element inside a web view in an iOS app.

这篇关于Xcode 6 Swift WKWebView键盘设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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