то, что я хочу сделать, когда я создаю native.newTextField установить опцию isSecure к ложным и заполнитель для «введите пароль»Corona SDK - native.newTextField - потерять фокус
и всякий раз, когда пользователь начала набрав , измените текстовое поле на 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
конец
--scene: показать --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)
Почему вы меняете isSecure значения? Держите его всегда 'true', он не вмешивается в' placeholder'. –
это мешает, по крайней мере, так, как я это делал. , если я сначала вызываю заполнитель, а затем isSecure, текст заполнителя исчезает. Перед: --Here заполнитель текста сбрасывается в "" \t \t passwordField.placeholder = "введите пароль" \t \t passwordField.isSecure = истина После: --Here текст-заполнитель сохраняет свою ценность. \t \t passwordField.isSecure = истинный \t \t passwordField.placeholder = "введите пароль" спасибо за помощь мне выяснить это. –