博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Getting Started with iOS Development Part4:iOS Scripting Mobile Keyboard
阅读量:6969 次
发布时间:2019-06-27

本文共 4369 字,大约阅读时间需要 14 分钟。

Mobile Keyboard

Sometimes when developing your game you might need to have access to the keyboard Input that your target platform provides, this is done straight forward in unity just by calling some attributes via scripting.

Using the Keyboard

GUI Elements

The keyboard will appear automatically when a user taps on editable GUI elements. Currently, GUI.TextField, GUI.TextArea and GUI.PasswordField are capable of automatic handling of keyboard. Please read GUI documentation to find out how to use these.

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.

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.
iPhoneKeyboardType.NumberPad Only numbers from 0 to 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.

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:

   
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.

   
visible Returns true if the keyboard is fully visible on the screen and can be used to enter characters.
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.

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.Open is called. iPhoneKeyboard.active returns true. iPhoneKeyboard.visible returns false. iPhoneKeyboard.area returns (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.

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);
 
Getting <wbr>Started <wbr>with <wbr>iOS <wbr>Development <wbr>Part4:iOS <wbr>Scripting <wbr>Mobile <wbr>Keyboard

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("", iPhoneKeyboardType.Default, false, false, true, true);
 
Getting <wbr>Started <wbr>with <wbr>iOS <wbr>Development <wbr>Part4:iOS <wbr>Scripting <wbr>Mobile <wbr>Keyboard

Classic keyboard

 
Getting <wbr>Started <wbr>with <wbr>iOS <wbr>Development <wbr>Part4:iOS <wbr>Scripting <wbr>Mobile <wbr>Keyboard

Alert keyboard

转载地址:http://xussl.baihongyu.com/

你可能感兴趣的文章
SVN版本还原
查看>>
使用SpringMVC创建支持向下兼容的版本化的API接口
查看>>
Chrome 显示 err_cert_authority_invalid 的处理方式
查看>>
简单理解倒排索引
查看>>
SpringAop在实际项目中的使用案例
查看>>
哪个对象才是锁?
查看>>
this关键字
查看>>
Python中字符串和datetime
查看>>
ng-Cordova插件之fileTransfer的使用
查看>>
基于struts1.框架的异常处理方案
查看>>
浅谈 Qt 内存管理
查看>>
【Qt】Qt之密码框不可选中、复制、粘贴、无右键菜单等【转】
查看>>
Flume中关于HDFS的sink配置
查看>>
Idea 社区版开发指南-1
查看>>
date命令转换unix时间戳
查看>>
/usr/lib目录属性更改引发的蝴蝶效应
查看>>
比禅道好用的项目管理 项目管理工具Redmine 各功能测试
查看>>
org.apache.commons 常用工具类
查看>>
TabHost的使用
查看>>
OpenGL超级宝典笔记——颜色
查看>>