Hello,
In my app, I have a textfield which is usually covered by the keyboard. To avoid this, I shift the display up and recreate the text field above when the user clicks on the text field. I also utilize the setKeyboardFocus function so that the user does not have to click on the field again to begin typing.
While this code works perfectly on android devices, the keyboard does not open on either the XCode simulator and iOS devices. Even when I click on the new text field, I do not get the keyboard.
If I remove the native.setKeyboardFocus( answerField ) line, the keyboard does show up after clicking on the new text field.
Any suggestions are greatly appreciated. Thanks!
Code:
[lua]
function userInputListener( event )
if event.phase == “began” then
transition.to(localGroup, {y = -100, time=500})
if textBox then
textBox:removeSelf()
textBox = nil
end
textBox = native.newTextBox( 24, 56, 352, 135) --244
textBox.font = native.newFont( “Helvetica-Bold”, 20 )
textBox:setTextColor( 255, 255, 255 )
--textBox.alpha = 1.0
textBox.hasBackground = false
textBox:addEventListener( “tap”, removeKeyboard )
textBox.text = text
storedText = tostring(event.target.text)
native.setKeyboardFocus( nil )
if answerField then
answerField:removeSelf()
answerField = nil
end
answerField = native.newTextField( 25, 214, 275, 38)
answerField.size = fontSize
answerField.text = storedText
answerField:addEventListener( “userInput”, shiftedListener )
answerField.inputType = “decimal”
native.setKeyboardFocus( answerField )
end
if event.phase == “submitted” or event.phase == “ended” then
submittedAnswer = tostring(event.target.text)
if(submittedAnswer:lower() == tostring(answer):lower())then
correct = 1
--local t = display.newText(“Correct”, 80, 310, null, 16)
else
correct = 0
end
end
end
[/lua]