Corona SDK - 文本输入框在屏幕左侧停留

我在 Corona 中有一个工作中的文本字段...我使用以下方法进行实例化:

local nameTextField = native.newTextField (centerX, roundedRect.y + roundedRect.height*1.7, 300, 80)

nameTextField:addEventListener( "userInput", textListener )

然后,我确保在 create 方法中将其添加到场景的 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 仍然留在屏幕上。 这在我的其他场景中不会发生。

这可能是什么原因??? 我该怎么解决???

点赞
用户5552488
用户5552488

似乎本地对象不能添加到显示组中,当你隐藏场景时,需要删除本地对象,请尝试以下操作:

添加场景:隐藏(事件)

function scene:hide(event)

   if nameTextField then
    nameTextField :removeSelf()
    nameTextField = nil
   end
end

scene:addEventListener("hide", scene)

希望这能帮到你!

2016-01-05 19:00:21
用户3041972
用户3041972

我相当确定这是因为本地变量的访问问题。

将此更改为

nameTextField = native.newTextField(centerX,roundedRect.y + roundedRect.height*1.730080

或者

function scene:create( event )
    sceneGroup = self.view
    sceneGroup:insert(nameTextField)
end

将此更改为

function scene:create( event )
    local sceneGroup = self.view
    sceneGroup:insert(nameTextField)
end
2016-01-06 01:54:08
用户1870706
用户1870706

首先,native.newTextField() 可以添加到 display.newGroup() 中。它们会随着组移动,但仍然位于显示层次结构的顶部。使用淡入淡出或交叉淡入淡出的场景无法隐藏文本字段,因为它们没有被移动。

由于看起来您的重叠层正在使用“渐隐”效果,因此在调用 showOverlay 时需要隐藏文本字段,并在完成重叠层后显示它们。

作用域也很重要。我无法确定您的代码的哪个部分创建了新的文本字段,但必须使其对您引用它的任何地方可见。

2016-01-10 23:57:45