【问题标题】:Corona SDK - TextField Gets Left On ScreenCorona SDK - TextField 留在屏幕上
【发布时间】:2016-04-09 15:39:46
【问题描述】:

我在电晕中有一个工作文本字段...我使用以下方法对其进行了实例化:

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 仍然留在屏幕上。 这不会发生在我的其他场景中。

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

【问题讨论】:

    标签: lua coronasdk


    【解决方案1】:

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

    由于看起来您的叠加层使用了“淡入淡出”,因此您需要在调用 showOverlay 时隐藏文本字段,并在完成叠加层时显示它们。

    范围也很重要。我不知道您正在创建新文本字段的代码的哪一部分,但它必须对您引用它的任何地方都是可见的。

    【讨论】:

      【解决方案2】:

      似乎无法将原生对象添加到显示组,您需要在隐藏场景时移除原生对象,试试这个:

      添加场景:隐藏(事件)

      function scene:hide(event)
      
         if nameTextField then
          nameTextField :removeSelf()
          nameTextField = nil
         end
      end
      
      scene:addEventListener("hide", scene)
      

      希望对您有所帮助!

      【讨论】:

        【解决方案3】:

        我很确定这是因为局部变量的访问问题。

        改变这个

        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
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-12-30
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多