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

How do you make sure a text field appears just right above the mobile system keyboard?

Discussion in 'UGUI & TextMesh Pro' started by Dehron, Feb 22, 2016.

  1. Dehron

    Dehron

    Joined:
    Jun 13, 2014
    Posts:
    7
    With all the different OEMs, resolutions, and different size system keyboards on mobile devices, how do you ensure that when a user clicks on a text field (to enter input) and the keyboard opens up, that the text field is right above the top of the keyboard?

    Not sure if that makes sense... I can explain further if necessary.

    The problem right now is that because of all the variables I mentioned above, we currently are just guessing on where to bump up the text field. It would be nicer if we could have it be based on where the top of keyboard is.

    Thank you in advance for any help with this!

    -Dehron
     
  2. feiting

    feiting

    Joined:
    Oct 26, 2012
    Posts:
    33
    http://docs.unity3d.com/ScriptReference/TouchScreenKeyboard.html
    Also possible using native code interop which is findable via a search for "Keyboard height" in the forums or "keyboard height unity" via google search.

    I have seen everything you mention be a valid issue, as iOS window measurements are used ignoring orientation, and timing messes up when the variable exists... but as far as simple use-case goes, the basic unity3d manual should be sufficient for your purpose. If it is zero, shove an invoke() after some number of seconds/(fractions of) so keyboard height isn't 0. If it is still 0, I would bug it