Corona SDK - TextField 留在屏幕上
Corona SDK - TextField Gets Left On Screen
我在 corona 中有一个可用的文本字段...我使用以下方法对其进行了实例化:
local nameTextField = native.newTextField (centerX, roundedRect.y + roundedRect.height*1.7, 300, 80)
nameTextField:addEventListener( "userInput", textListener )
然后我确保在创建方法中将其添加到场景的 self.view 中:
function scene:create( event )
local sceneGroup = self.view
sceneGroup:insert(nameTextField)
end
整个场景使用showoverlay
方法显示。
composer.showOverlay( "renameoverlay", options )
当我使用hide overlay
隐藏场景时:
composer.hideOverlay( "fade", 400 )
即使在使用上面的代码隐藏了整个场景之后,nameTextField 仍然留在屏幕上。
这不会发生在我的其他场景中。
这可能是什么原因造成的????
我该如何解决这个问题???
好像原生对象不能加入dispaly组,隐藏场景时需要移除原生对象,试试这个:
添加 scene:hide(事件)
function scene:hide(event)
if nameTextField then
nameTextField :removeSelf()
nameTextField = nil
end
end
scene:addEventListener("hide", scene)
希望对您有所帮助!
我很确定这是因为局部变量的访问问题。
改变这个
local nameTextField = native.newTextField (centerX, roundedRect.y + roundedRect.height*1.7, 300, 80)
至此
nameTextField = native.newTextField (centerX, roundedRect.y + roundedRect.height*1.7, 300, 80)
或这个
function scene:create( event )
local sceneGroup = self.view
sceneGroup:insert(nameTextField)
end
至此
function scene:create( event )
sceneGroup = self.view
sceneGroup:insert(nameTextField)
end
首先,native.newTextField() 可以添加到 display.newGroup() 中。将随组一起移动,但它们仍然位于显示层次结构的顶部。使用淡入淡出或交叉淡入淡出的场景无法隐藏文本字段,因为它们没有被移动。
因为看起来您的叠加层正在使用 "fade",您需要在调用 showOverlay 时隐藏文本字段,并在完成叠加层时显示它们。
范围也很重要。我无法确定您正在创建新文本字段的代码的哪一部分,但它必须对您引用它的任何地方可见。
我在 corona 中有一个可用的文本字段...我使用以下方法对其进行了实例化:
local nameTextField = native.newTextField (centerX, roundedRect.y + roundedRect.height*1.7, 300, 80)
nameTextField:addEventListener( "userInput", textListener )
然后我确保在创建方法中将其添加到场景的 self.view 中:
function scene:create( event )
local sceneGroup = self.view
sceneGroup:insert(nameTextField)
end
整个场景使用showoverlay
方法显示。
composer.showOverlay( "renameoverlay", options )
当我使用hide overlay
隐藏场景时:
composer.hideOverlay( "fade", 400 )
即使在使用上面的代码隐藏了整个场景之后,nameTextField 仍然留在屏幕上。 这不会发生在我的其他场景中。
这可能是什么原因造成的???? 我该如何解决这个问题???
好像原生对象不能加入dispaly组,隐藏场景时需要移除原生对象,试试这个:
添加 scene:hide(事件)
function scene:hide(event)
if nameTextField then
nameTextField :removeSelf()
nameTextField = nil
end
end
scene:addEventListener("hide", scene)
希望对您有所帮助!
我很确定这是因为局部变量的访问问题。
改变这个
local nameTextField = native.newTextField (centerX, roundedRect.y + roundedRect.height*1.7, 300, 80)
至此
nameTextField = native.newTextField (centerX, roundedRect.y + roundedRect.height*1.7, 300, 80)
或这个
function scene:create( event )
local sceneGroup = self.view
sceneGroup:insert(nameTextField)
end
至此
function scene:create( event )
sceneGroup = self.view
sceneGroup:insert(nameTextField)
end
首先,native.newTextField() 可以添加到 display.newGroup() 中。将随组一起移动,但它们仍然位于显示层次结构的顶部。使用淡入淡出或交叉淡入淡出的场景无法隐藏文本字段,因为它们没有被移动。
因为看起来您的叠加层正在使用 "fade",您需要在调用 showOverlay 时隐藏文本字段,并在完成叠加层时显示它们。
范围也很重要。我无法确定您正在创建新文本字段的代码的哪一部分,但它必须对您引用它的任何地方可见。