单击提交后如何隐藏native.newTextField? [英] How to hide native.newTextField after clicking submit?

查看:107
本文介绍了单击提交后如何隐藏native.newTextField?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让用户名称一次垂直地淡入一个字母.示例:Adam"A"将在1秒后出现,"d"将在显示的A下3秒后出现,"a"将在显示d的5秒后出现,"m"将在显示a的7秒后出现.视觉效果会产生一种多米诺骨牌效应.当它们出现时,它们将始终显示在屏幕上.

I'm trying trying to have users name fade in one letter at a time vertically. Example: Adam "A" would appear after 1 second , "d" would appear after 3 seconds under the displayed A, "a" would appear after 5 seconds under the displayed d, "m" would appear after 7 seconds under the displayed a. The visuals would have a sort of domino effect.When they appear they would stay displayed on screen.

当我注释掉userNameField:removeSelf()时,代码可以正常工作.我得到了想要的效果,但是问题是我仍然显示了userNamefield.

When if I comment out userNameField:removeSelf () then the code works fine. I get the effect I want, but the problem is that I still have the userNamefield showing.

如果您需要查看更多代码,请告诉我.

Please let me know if you need to see more code.

local greeting = display.newText( "Greetings, enter your name",0,0,native.systemFont, 20 )
greeting.x = display.contentWidth/2
greeting.y = 100

local submitButton = display.newImage( "submit.png"  ,display.contentWidth/2, display.contentHeight - 50 )

local userNameField = native.newTextField( display.contentWidth * 0.5 , 150, 250, 45)
userNameField.inputtype = "defualt"


local incrementor = 0
function showNameLetters()

userNameField:removeSelf( )
if incrementor <= string.len ("userNameField.text") then
    incrementor = incrementor + 1
    personLetters = string.sub (userNameField.text, incrementor,incrementor)
    display_personLetters = display.newText (personLetters, 290,30*incrementor, native.systemFont, 30)
        display_personLetters.alpha = 0
    transition.to(display_personLetters,{time = 3000, alpha = 1, onComplete = showNameLetters})
end
end

更新:

通过在函数中添加userNameField.isVisible = false,我找到了解决问题的方法.

I've found a solution to my problem, by adding userNameField.isVisible = false in my function.

我也发现了一些很奇怪的东西,并希望有人解释为什么会这样.如果我添加greeting:removeSelf()和submitButton:removeSelf()(我在下面的代码中将它们注释掉了,向您展示了将它们放置在哪里进行测试).我得到的只是第一个字母淡入的奇怪结果.如果我将greeting.isVisible = false设置为submitButton.isVisible = false.该代码可以正常工作.

I've also found something very weird, and wish to have someone explain why this happens. If I add greeting:removeSelf() and submitButton:removeSelf() (I've commented them out in my code below to show you where I put them for testing). I get weird result of only the first letter fading in. If i set greeting.isVisible = false and submitButton.isVisible = false. The code works fine.

我很困惑为什么object:removeSelf()无法正常工作.有人可以帮我清理一下吗.

I'm so confused why object:removeSelf() wouldn't work. Can someone please clear this up for me.

也就是说,如果我替换以下行:

That is, if I replace the following line:

userNameField:removeSelf( )

具有:

userNameField.isVisible = false

然后该应用正常运行.请建议我为什么/这个问题的任何解决方案.提前谢谢...

then the app works fine. Please suggest me why/ any solution for the question. THanks in advance...

推荐答案

似乎您要多次调用 showNameLetters ,这意味着您要多次删除本机文本字段.删除它,并在删除它之前检查是否为零:

It seems like you're calling the showNameLetters multiple times, this means that you're removing the native text field more than once. Nil it and check for nil before removing it like this:

if userNameField ~= nil then
 userNameField:removeSelf()
 userNameField = nil
end

这篇关于单击提交后如何隐藏native.newTextField?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆