ios - 如何使ios键盘返回键统一提交输入?

标签 ios iphone unity-game-engine keyboard

我有一个 Unity UI 的输入字段和一个文本框。当我使用 Input.GetKeyDown (KeyCode.Return) 时,它仅适用于 OS X 和 PC 版本,不适用于 iOS 版本。 iOS 键盘的 Return 键什么都不做。我也尝试过这些事件,但即使那样也不起作用。

有人请告诉我这个问题的解决方案,如果有的话?

最佳答案

虽然我想不出直接在 iOS 上利用返回键的方法,但有一种方法可以通过使用 TouchScreenKeyboard 的“提交”键来实现。 Unity 中的类

具体来说,它有一个变量TouchScreenKeyboard.done指示用户是否按下了任何移动设备(iOS、Android WP)上的“提交”(或等效)按钮

您还可以检查 wasCanceled变量以查看用户是否取消了输入。

例子

public class TouchKeyboardExample : Monobehaviour {

    private TouchScreenKeyboard touchScreenKeyboard;
    private string inputText = string.Empty;

    void Start () {
        touchScreenKeyboard = TouchScreenKeyboard.Open(inputText, TouchScreenKeyboardType.Default);
    }

    void Update () {
        if(touchScreenKeyboard == null)
            return;
        inputText = touchScreenKeyboard.text;
        if(touchScreenKeyboard.done)
            Debug.Log("User typed in "+inputText);
        if(touchScreenKeyboard.wasCanceled)
            Debug.Log("User canceled input");
    }

}

关于ios - 如何使ios键盘返回键统一提交输入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31803135/

相关文章:

unity-game-engine - Google Play 游戏服务登录时应用程序崩溃

ios - 断言当前线程是主线程的单元测试 [iOS]

ios - 我如何阻止 ios 自动将 cookie 添加到我的 NSMutableURLRequest

ios - jQuery.ajax 重新加载页面而不是在 iOS 上的 Safari 中执行 ajax 请求

iphone - NSDateFormatter,我做错了什么还是这是一个错误?

c# - 如何对不透明代码进行单元测试?

unity-game-engine - Unity3D,无法点击带有Canvas组件的面板上的按钮

ios - Firebase、 swift : Create a time checker in the background similar to the Snapchat streak system that performs an action when the time runs out

iphone - sizeWithFont:constrainedToSize:lineBreakMode:使用UILineBreakModeClip时不正确?

iPhone UITableView 同时滚动