Corona sdk - native.newTextField - 失去焦点

时间:2016-06-20 19:05:21

标签: lua sdk corona

我想要完成的是当我创建native.newTextField时将isSecure选项设置为false并将占位符设置为“键入您的密码”

每当用户开始输入时,将文本字段更改为isSecure = true,以获得*符号。 用我的方法我遇到的问题是我的文本字段在第一个字母后失去焦点。

这是我的代码:

local function fieldHandler( event )
    if ( "began" == event.phase ) then
        -- This is the "keyboard has appeared" event
        -- In some cases you may want to adjust the interface when the keyboard appears.
    elseif ( "ended" == event.phase ) then
        -- This event is called when the user stops editing a field: for example, when they touch a different field
        if(event.target.id == "password" and event.target.text == "")then
            event.target.isSecure = false
            passwordField.placeholder = "type your password"
        end

    elseif ( "editing" == event.phase ) then
        if(event.target.id == "password" and string.len(event.target.text) >0 ) then
            event.target.isSecure = true
            --native.setKeyboardFocus( event.target )   
        end
    elseif ( "submitted" == event.phase ) then

        -- Hide keyboard
        native.setKeyboardFocus( nil )
    end

- 场景:显示 --Did

        local passwordField = native.newTextField( _CX - fieldWidth/2, passwordFieldBg.y, fieldWidth, 40 )
    passwordField.id = "password"
    passwordField:addEventListener( "userInput", fieldHandler ) 
    group:insert( passwordField)
    passwordField.hasBackground = false
    passwordField.anchorX = 0
    passwordField.placeholder = "type your password"
    passwordField.autocorrectionType = "UITextAutocorrectionTypeNo"
    passwordField.isSecure = false
    passwordField.font =  native.newFont( gM.fontDin )
    passwordField:resizeFontToFitHeight()

请帮我解决这个问题,或者我可以使用的其他方法。

感谢,

版本2016.2883(2016.5.17)

1 个答案:

答案 0 :(得分:0)

我认为没有必要更改input = getDirectory("Input directory"); output = getDirectory("Output directory"); Dialog.create("File type"); Dialog.addString("File suffix: ", ".avi", 5); Dialog.show(); suffix = Dialog.getString(); processFolder(input); function processFolder(input) { list = getFileList(input); for (i = 0; i < list.length; i++) { if(File.isDirectory(input + list[i])) processFolder("" + input + list[i]); if(endsWith(list[i], suffix)) processFile(input, output, list[i]); } } function processFile(input, output, file) { open(input + file); run("Make Substack...", " slices=1-293-5"); run("AVI... ", "compression=None frame=1.96 save=&output+&file"); close(); close(); } 值,但您可以将其移至isSecure阶段:

began