如何使ios键盘的返回键统一提交输入? [英] how make to make ios keyboard's return key submit input in unity?

查看:118
本文介绍了如何使ios键盘的返回键统一提交输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Unity UI的输入字段和一个文本框.当我使用Input.GetKeyDown(KeyCode.Return)时,它仅适用于OS X和PC版本,而不适用于iOS版本. iOS键盘的Return键不执行任何操作.我也尝试过这些事件,但是即使那样也无法正常工作.

I have a Unity UI's input field and a text box. When I use Input.GetKeyDown (KeyCode.Return), it only works on the OS X and PC build and not on the iOS build. iOS keyboard's Return key does nothing. I have tried the events, too, but it doesn't work even then.

有人告诉我解决这个问题的方法吗?

Somebody please tell me the solution to this problem if there is any?

推荐答案

虽然我无法想到直接在iOS上利用返回键的方法,但可以通过使用提交"键来实现 TouchScreenKeyboard Unity中的类

While I can't think of a way to harness the return key directly on iOS, there is a way to do so with the "Submit" key using the TouchScreenKeyboard class in Unity

具体来说,它具有变量 TouchScreenKeyboard.done 来指示用户是否已在任何移动设备(iOS,Android WP)上按下提交"(或等效按钮)

Specifically, it has a variable TouchScreenKeyboard.done to indicate whether the user has pressed the "Submit" (or equivalent) button on any mobile device (iOS, Android WP)

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

You can also check the wasCanceled variable to see whether the user canceled the input.

示例

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键盘的返回键统一提交输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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