newTextField positioning is wrong for iOS iPhones (iPads and Android fine)
This issue has been reported to Corona as a bug - Case 42865.
newTextField positioning is wrong for iOS iPhones (iPads and Android fine)
This issue has been reported to Corona as a bug - Case 42865.
UPDATE: The following post was written prior to Daily Build 2830, which appears to resolve these issues. However, I have not tested CoronaLabs’ fix on older model iOS devices. But before implementing the below recommendations, I would advise you use the latest daily build and test it on your devices, first.
After numerous hours of testing the latest native.newTextField changes in Corona made here in mid-2015, I have discovered that the x,y,width and height of the field works properly on Android and iPad’s only. They also appear to work properly on iPhone, but only in the Corona simulator - but definitely NOT on iPhone devices. On my iPhone 5 running iOS 8.2 and iPhone 6 Plus running iOS 9, I discovered the same flaws with position calculations which existed in Corona’s previous implementation.
I solved this problem and am publishing it here for your benefit.
Through trial and error, I tweaked the values until I found the proper coefficients to multiply any x,y,width or height position by in order to properly display on both the iPhone 5 and the iPhone 6 Plus. I discovered differing values for both devices, and different values even with slightly similar screen resolution ratios - so recognizing this, I realized this problem needed to be solved using the algebraic straight-line method.
As a result, it works perfectly in my app.
In other words, on Android and iPad’s, the coefficient is always 1 (one). But for iPhones, every calculation for x,y,width or height position must be calculated as .876-(display.viewableContentWidth*.00059). Here is some sample code:
function doNativeNewTextField (x,y,w,h)
local c = 1 --coefficient fine for Android and iPads
if system.getInfo(“platformName”)==“iPhone OS” then
if string.match(system.getInfo(“model”),“iPa”) then
– if iPad do nothing - see EXTRA NOTE below to be sure
else --this is for iOS iPhones only
c = .876-(display.viewableContentWidth*.00059) --calculate coefficient
end
end
obj=native.newTextField( x*c,y*c,w*c,h*c )
return obj
end
NOTE: I also found that the textField font size varies between platforms, and in fact, positioning must be changed on Android to cause it to appear the same ‘size’ as on iOS devices. This is discussed at: https://forums.coronalabs.com/topic/59257-newtextfield-font-size-for-android-and-ios-not-the-same/
EXTRA NOTE: This code works on my Amazon Fire Android, HTC One Android, iPhone 5, iPhone 6 Plus and iPad2…but has NOT yet been tested on the newer iPads. I believe it should work the same on other iterations of iPad hardware - but this is only an assumption.
UPDATE: The following post was written prior to Daily Build 2830, which appears to resolve these issues. However, I have not tested CoronaLabs’ fix on older model iOS devices. But before implementing the below recommendations, I would advise you use the latest daily build and test it on your devices, first.
After numerous hours of testing the latest native.newTextField changes in Corona made here in mid-2015, I have discovered that the x,y,width and height of the field works properly on Android and iPad’s only. They also appear to work properly on iPhone, but only in the Corona simulator - but definitely NOT on iPhone devices. On my iPhone 5 running iOS 8.2 and iPhone 6 Plus running iOS 9, I discovered the same flaws with position calculations which existed in Corona’s previous implementation.
I solved this problem and am publishing it here for your benefit.
Through trial and error, I tweaked the values until I found the proper coefficients to multiply any x,y,width or height position by in order to properly display on both the iPhone 5 and the iPhone 6 Plus. I discovered differing values for both devices, and different values even with slightly similar screen resolution ratios - so recognizing this, I realized this problem needed to be solved using the algebraic straight-line method.
As a result, it works perfectly in my app.
In other words, on Android and iPad’s, the coefficient is always 1 (one). But for iPhones, every calculation for x,y,width or height position must be calculated as .876-(display.viewableContentWidth*.00059). Here is some sample code:
function doNativeNewTextField (x,y,w,h)
local c = 1 --coefficient fine for Android and iPads
if system.getInfo(“platformName”)==“iPhone OS” then
if string.match(system.getInfo(“model”),“iPa”) then
– if iPad do nothing - see EXTRA NOTE below to be sure
else --this is for iOS iPhones only
c = .876-(display.viewableContentWidth*.00059) --calculate coefficient
end
end
obj=native.newTextField( x*c,y*c,w*c,h*c )
return obj
end
NOTE: I also found that the textField font size varies between platforms, and in fact, positioning must be changed on Android to cause it to appear the same ‘size’ as on iOS devices. This is discussed at: https://forums.coronalabs.com/topic/59257-newtextfield-font-size-for-android-and-ios-not-the-same/
EXTRA NOTE: This code works on my Amazon Fire Android, HTC One Android, iPhone 5, iPhone 6 Plus and iPad2…but has NOT yet been tested on the newer iPads. I believe it should work the same on other iterations of iPad hardware - but this is only an assumption.