Unity 手机键盘

iOS

Using the Keyboard 使用键盘

GUI Elements (GUI元素)

The keyboard will appear automatically when a user taps on editable GUI elements. Currently, GUI.TextFieldGUI.TextArea andGUI.PasswordField will display the keyboard; see the GUI class documentation for further details.

当用户点击可编辑的GUI元素时键盘将自动出现。当前,GUI.TextField、GUI.TextArea和GUI.PasswordField会显示键盘;更多的细节请查看GUI类

Manual Keyboard Handling 手动键盘操作

Use the iPhoneKeyboard.Open function to open the keyboard. Please see the iPhoneKeyboard scripting reference for the parameters that this function takes.

使用iPhoneKeyboard.Open方法来打开键盘。关于iPhoneKeyboard的详细参数请查看iPhoneKeyboard脚本参考。

Keyboard Type Summary 键盘类型总结

The Keyboard supports the following types:

键盘支持以下几种类型:

  • iPhoneKeyboardType.Default
    Letters. Can be switched to keyboard with numbers and punctuation.
    字母键盘。可以切换到数字和标点键盘。
  • iPhoneKeyboardType.ASCIICapable
    Letters. Can be switched to keyboard with numbers and punctuation.
    字母键盘。可以切换到数字和标点键盘。
  • iPhoneKeyboardType.NumbersAndPunctuation
    Numbers and punctuation. Can be switched to keyboard with letters.
    数字和标点键盘。可以切换到字符键盘。
  • iPhoneKeyboardType.URL
    Letters with slash and .com buttons. Can be switched to keyboard with numbers and punctuation.
    包含斜线以及.com按钮的字母键盘。可以切换到数字和标点键盘。
  • iPhoneKeyboardType.NumberPad
    Only numbers from 0 to 9.  仅0-9九个数字按键。
  • iPhoneKeyboardType.PhonePad
    Keyboard used to enter phone numbers.  拨号键盘。
  • iPhoneKeyboardType.NamePhonePad
    Letters. Can be switched to phone keyboard. 
    字母键盘。能够切换到拨号键盘。
  • iPhoneKeyboardType.EmailAddress
    Letters with @ sign. Can be switched to keyboard with numbers and punctuation.
    包含@键的字母键盘。能够切换到数字和标点键盘。

Text Preview 文本预览

By default, an edit box will be created and placed on top of the keyboard after it appears. This works as preview of the text that user is typing, so the text is always visible for the user. However, you can disable text preview by setting iPhoneKeyboard.hideInput to true. Note that this works only for certain keyboard types and input modes. For example, it will not work for phone keypads and multi-line text input. In such cases, the edit box will always appear. iPhoneKeyboard.hideInput is a global variable and will affect all keyboards.

默认情况下,编辑框将被创建并置于键盘的上方。这是作为用户输入的文本预览,因此对用户文本总是可见的。当然,你可以通过设置iPhoneKeyboard.hideInput=true来禁用文本预览。请注意,这仅适用于某些键盘类型和输入模式。例如:不能工作于拨号键盘以及多行文本输入。在这种情况下,编辑框将始终出现。iPhoneKeyboard.hideInput是一个全局变量,会影响所有的键盘。

Keyboard Orientation 键盘方向

By default, the keyboard automatically follows the device orientation. To disable or enable rotation to a certain orientation, use the following properties available in iPhoneKeyboard:

默认情况下,键盘将自动跟踪设备方向。要禁用或启用某个方向的旋转,可以设置iPhoneKeyboard一下属性。

  • autorotateToPortrait
    Enable or disable autorotation to portrait orientation (button at the bottom).
    启用或禁用自动旋转到纵向(按钮在底部)。
  • autorotateToPortraitUpsideDown
    Enable or disable autorotation to portrait orientation (button at top).
    启用或禁用自动旋转到纵向(按钮在顶部)。
  • autorotateToLandscapeLeft
    Enable or disable autorotation to landscape left orientation (button on the right).
    启用或禁用自动旋转到左横向(键盘在右侧) 。
  • autorotateToLandscapeRight
    Enable or disable autorotation to landscape right orientation (button on the left).
    启用或禁用自动旋转到右横向(键盘在左侧)。

Visibility and Keyboard Size 键盘可见性和尺寸

There are three keyboard properties in iPhoneKeyboard that determine keyboard visibility status and size on the screen.

iPhoneKeyboard有三个参数设置键盘的在屏幕上的可见性以及大小属性。

  • visible  可见性
    Returns true if the keyboard is fully visible on the screen and can be used to enter characters.
    如果键盘在屏幕上完全可见并且可以输入字符,返回true。
  • area  区域
    Returns the position and dimensions of the keyboard.
    返回键盘的位置及尺寸。
  • active  激活
    Returns true if the keyboard is activated. This property is not static property. You must have a keyboard instance to use this property.
    如果键盘被激活,返回true。这是一个非静态属性,使用这个属性你必须有一个键盘实例。

Note that iPhoneKeyboard.area will return a rect with position and size set to 0 until the keyboard is fully visible on the screen. You should not query this value immediately after iPhoneKeyboard.Open. The sequence of keyboard events is as follows:

请注意:直到键盘完全显示在屏幕上之前,iPhoneKeyboard.area返回的位置和大小都将为0。你不能在设置iPhoneKeyboard.Open之后立即查询此值。键盘事件的顺序如下:

  • iPhoneKeyboard.Open is called. iPhoneKeyboard.active returns true. iPhoneKeyboard.visible returns false. iPhoneKeyboard.area returns (0, 0, 0, 0). 
    当iPhoneKeyboard.Open被调用,iPhoneKeyboard.active返回true,iPhoneKeyboard.visible返回false,iPhoneKeyboard.area返回(0,0,0,0);
  • Keyboard slides out into the screen. All properties remain the same. 
    当键盘滑进屏幕。所有属性保持不变。
  • Keyboard stops sliding. iPhoneKeyboard.active returns true. iPhoneKeyboard.visible returns true. iPhoneKeyboard.area returns real position and size of the keyboard. 
    当键盘停止滑动,完全在屏幕上显示。iPhoneKeyboard.active返回true,iPhoneKeyboard.visible返回true,iPhoneKeyboard.area返回键盘的真实位置和大小。

Secure Text Input 安全的文本输入

It is possible to configure the keyboard to hide symbols when typing. This is useful when users are required to enter sensitive information (such as passwords). To manually open keyboard with secure text input enabled, use the following code:

能够设置在键盘输入时隐藏字符。当用户输入敏感信息时这是非常有用的(如输入密码)。要手动打开文本输入的安全性设置,请使用下面的代码:

iPhoneKeyboard.Open("", iPhoneKeyboardType.Default, false, false, true);

Hiding text while typing 输入时隐藏文本

Alert keyboard 警醒键盘

To display the keyboard with a black semi-transparent background instead of the classic opaque, call iPhoneKeyboard.Open as follows:

要显示一个黑色半透明的背景键盘而非经典的不透明键盘,调用iPhoneKeyboard.Open如下:

iPhoneKeyboard.Open("", iPhoneKeyboardType.Default, false, false, true, true);

Classic keyboard 经典键盘

Alert keyboard 警醒键盘

Android

Unity Android reuses the iOS API to display system keyboard. Even though Unity Android supports most of the functionality of its iPhone counterpart, there are two aspects which are not supported:

Unity Android 在显示系统键盘方面重用了IOS的API,虽然Unity Android支持大部分的与IPhone对应的功能,但是有以下两点功能不支持:

  • iPhoneKeyboard.hideInput
  • iPhoneKeyboard.area

Please also note that the layout of a iPhoneKeyboardType can differ somewhat between devices.

请注意:iPhoneKeyboardType 的样式在不同的设备上有所不同。

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值