Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

iOS Mobile Keyboard Problems

Discussion in 'iOS and tvOS' started by El3et, Feb 4, 2013.

  1. El3et

    El3et

    Joined:
    Jan 19, 2011
    Posts:
    97
    Hi everyone.

    I need to know if it is possible to keep an instance of a keyboard displayed even when the user presses the done button when the text typed by the user doesn't equal a pre determined string value.

    For example.

    User inputs Hello and presses Done - Strings match and keyboard is removed.
    User inputs Bye and presses done - Strings don't match and keyboard does not move.

    I have tried to use keyboard.done however the keyboard just retracts and reappears (deletes the instance and creates a new one).

    Thanks.
     
  2. zackivano

    zackivano

    Joined:
    Mar 20, 2012
    Posts:
    11
    Hello El3et,
    we have similar problem, look at my thread here: http://forum.unity3d.com/threads/168515-How-to-leave-keyboard-always-opened-and-get-multiple-inputs
    I can tell you that there's no way with the Unity TouchScreenKeyboard class to achieve what you need as I crashed my head for 2 days without success.
    Every time the user press Done the keyboard will close, then if you set the focus again on the textfield (I'm using NGUI so for me is the UIInput class) the keyboard will pop up again.
    The only way, I think is to create a custom ios keyboard plugin in OBJ-C to catch the Done event without the closing/opening animation, but i'm not so familiar with OBJ-C so I need to be pointed to the right direction to create such plugin.
    Here's the part of the code I used for the modified NGUI UIInput class:

    Code (csharp):
    1.  
    2. // ~ lines 300 in NGUI UIInput.cs
    3. if (mKeyboard.done)
    4.             {
    5.                 if (!isGameInput) // this is a bool to set the normal behavior for UIInput
    6.                 {   //normal UIInput behavior
    7.                     mKeyboard = null;
    8.                     current = this;
    9.                     if (onSubmit != null) onSubmit(mText);
    10.                     if (eventReceiver == null) eventReceiver = gameObject;
    11.                     eventReceiver.SendMessage(functionName, mText, SendMessageOptions.DontRequireReceiver);
    12.                     current = null;
    13.                     selected = false;
    14.                 }
    15.                 else {  //Modified UIInput behavior
    16.                     UICamera.selectedObject = gameObject; // once the done is pressed set back the focus on the UIInput object
    17.                     OnSelect(true); // the routine that open again the keyboard ~ lines 200 in UIInput
    18.                     if (onSubmit != null) onSubmit(mText);
    19.                     if (eventReceiver == null) eventReceiver = gameObject;
    20.                     eventReceiver.SendMessage(functionName, mText, SendMessageOptions.DontRequireReceiver);
    21.                 }
    22.             }
    The side effect of this code is that once the done event is catch the keyboard start to falling down a bit and then go up again in a bunch of frame, so we can see a little jump down of the keyboard... ugly but that's it. :(
    If some OBJ-C guru around here could help us it will be great! ;)
    Thanks,
    IZLogic