- Home /
HELP Move Screen Up when TouchKeyboard is open
It covers my NGUI Input Box. Any suggestions please? I am a noob. :(
$$anonymous$$aybe this helps:
On Android, when the on-screen keyboard is enabled, it causes an OnApplicationFocus( false ) event. Additionally, if you press Home at the moment the keyboard is enabled, the OnApplicationFocus() event is not called, but OnApplicationPause() is called ins$$anonymous$$d.
https://docs.unity3d.com/ScriptReference/$$anonymous$$onoBehaviour.OnApplicationFocus.html
Answer by highpockets · Mar 26, 2019 at 09:15 AM
The registration form is likely the game object that contains each field and you should be able to move it like so:
registrationFormObject.transform.position = new Vector2(desiredXValue, desiredYValue);
If you wanted to do it smoothly so it doesn't just pop up there from one frame to another you could add a lerp function for example:
float timeCount = 0.0f;
float offset = 50.0f; //Amount to move the form up
Vector2 startPos;
Vector2 endPos;
void Start(){
startPos = registrationFormObject.transform.position;
endPos = new Vector2(registrationFormObject.transform.position.x, registrationFormObject.transform.position.y + offset);
}
voidUpdate(){
if( TouchScreenKeyboard.visible ){
registrationFormObject.transform.position = Vector2.Lerp(startPos, endPos, timeCount);
timeCount = timeCount + Time.deltaTime;
}
}
I tried this but it is not working the form is moving to the lower right corner. I have a form which has three input fields , for 1st and 2nd input field there is no need to movement required. but when we type in the 3rd input field the keyboard hides the field. So I attached the script to third input field and the canvas. Here is my script: public GameObject registrationFormObject; float timeCount = 0.0f; float offset = 50.0f; //Amount to move the form up Vector2 startPos; Vector2 endPos;
void Start()
{
startPos = registrationFormObject.transform.position;
endPos = new Vector2(registrationFormObject.transform.position.x, registrationFormObject.transform.position.y + offset);
}
void Update()
{
if (TouchScreen$$anonymous$$eyboard.visible)
{
registrationFormObject.transform.position = Vector2.Lerp(startPos, endPos, timeCount);
timeCount = timeCount + Time.deltaTime;
}
}
What have you set to registrationFormObject?? $$anonymous$$ake it a public variable and attach the object in the editor or do this:
GameObject registrationFormObject;
void Start(){
registrationFormObject = GameObject.Find("ObjectName");
}
$$anonymous$$y script was just an example, but I strongly doubt that 50.0f is the right number for the offset you want. You'll have to play with the offset value a bit to find the right distance to move the object.
I would think that you would want to move the whole form so you don't have the field you want to move overlapping another field, but maybe you have enough space between fields.
Cheers,
I have made it public and added the input field to registrationFormObject
Your answer
![](https://koobas.hobune.stream/wayback/20220613102711im_/https://answers.unity.com/themes/thub/images/avi.jpg)