- Home /
How to get native resolution of mobile devices
Using Unity 4.6.3f1 - I'm trying to resize a RectTransform to accomodate the size of the TouchScreenKeyboard when it is open. I've got the following code which should work:
keyboardHeight = TouchScreenKeyboard.area.height * refResolution.x / (float)Screen.width;
GetComponent<RectTransform> ().offsetMin = new Vector2(0f, keyboardHeight);
The problem is that my Canvas is scaled according to screen width, but the Screen.width property does not report the native screen size of the iPad 2 (probably due to quality/performance settings). Since TouchScreenKeyboard.area.height seems to be in native size, how would I go about resizing the RectTransform properly?
Ok I figured out myself that using the current Canvas scale factor I can translate the native keyboard size to canvas reference resolution:
float keyboardVerticalOffset = keyboardHeight / canvas.transform.localScale.y; GetComponent ().offset$$anonymous$$in = new Vector2(0f, keyboardVerticalOffset);
However it doesn't seem to give the correct offset. There's a considerable gap between the keyboard and the bottom of the panel :(
Any ideas?
What does Screen.width return for you on the iPad2 then?
It returns 576, which corresponds to the Auto (Best Performance) setting listed on this page:
http://answers.unity3d.com/questions/398920/ios-best-performance-gives-odd-resolutions-unity-4.html
I realize now, after reading a question on another forum, that the Touchscreen$$anonymous$$eyboard.area.height always includes the "mobileinput" area, even if it has been hidden by setting hide$$anonymous$$obileInput to true on InputField - leaving a big gap on the screen in such cases. Not very nice. So the temp workaround is to hide the inputfield and set hide$$anonymous$$obileInput to false for now. Wish it could be different!