I’m having difficulty adjusting a text field’s position on screen after it is created. I see the docs say that text fields are not affected by groups, but suggests you can still alter their properties directly.
[text]Also, they do not inherit display group properties like isVisible, x, y and alpha. If you need to set display properties on native objects, apply them to the objects directly.[/text]
I’m attempting to shift the text field up on screen by the same amount that I shift my entire display to make room for the keyboard when the text field is activated. All the Corona display objects move (as expected) but I can never get the native text field to shift position. Here’s the code I currently have:
[lua]-- height of keyboard on non-retina iPhone
local keyboardHeight = 216
–Textfield listener
local function textListener( event )
if event.phase == “began” then
– user begins editing textField, shift screen and text field up
display.getCurrentStage().y = -keyboardHeight
defaultField.y = 690 + defaultField.contentHeight/2 - keyboardHeight
elseif event.phase == “ended” or event.phase == “submitted” then
– remove keyboard and shift screen and text field down to default position
native.setKeyboardFocus( nil )
display.getCurrentStage().y = 0
defaultField.y = 690 + defaultField.contentHeight/2
end
end
– Create our Text Field
defaultField = native.newTextField( (display.contentWidth - 580)/2, 690, 580, 100 )
defaultField:addEventListener( “userInput”, textListener )[/lua]
With this code, the display stage correctly shifts up and down, but the [lua]defaultField[/lua] textField never moves. I’ve also tried using [lua]displayObject:translate(x, y)[/lua] instead of modifying the [lua]y[/lua] component directly, but the result is the same.
Anyone had success moving a native UI after it is created? [import]uid: 178289 topic_id: 24285 reply_id: 124862[/import]