且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

密码字段的键盘仅在iOS 12上从azerty切换到qwerty(有时)

更新时间:2023-12-04 14:54:02

我已经为我的项目找到了解决方案,也许它可以对某人有所帮助.

I've found a solution for my project, maybe it can help someone.

我注意到了:

  • 在我的登录页面(带有1个安全UITextField)中,键盘为AZERTY
  • 在我的登录页面(带有2个安全UITextField)中,键盘为QWERTY
  • 在我的帐户页面(带有2个安全UITextField)中,键盘是AZERTY
  • in my login page (with 1 secure UITextField), keyboard was AZERTY
  • in my signin page (with 2 secure UITextField), keyboards were QWERTY
  • in my account page (with 2 secure UITextField), keyboards were AZERTY

在登录页面和帐户页面之间进行了一段时间的比较之后,我意识到在我的帐户页面中,安全文本字段之前的文本字段是.numberPad文本字段.

After a while of comparison between signin and account pages, I've realized that in my account page, the textfield before secure textfield was a .numberPad textfield.

因此,在我的登录xib文件中,我已将安全文本字段设置为.numberPad,并在textFieldDidBeginEditing中将其设置为.default.然后在textFieldDidEndEditing中再次返回到.numberPad,因为如果没有,则键盘第二次出现在QWERTY中.现在,我的安全文本字段位于AZERTY.

So in my login xib file, I've set my secure textfields to .numberPad and I set them to .default in textFieldDidBeginEditing. And back to .numberPad again in textFieldDidEndEditing because if not, keyboards appeared in QWERTY the second time. Now, my secure textfields are in AZERTY.

func textFieldDidBeginEditing(_ textField: UITextField) {
    if ( textField == pwdTextField || textField == pwd2TextField ) {
        textField.keyboardType = .default;
    }
    // do other stuffs
}

func textFieldDidEndEditing(_ textField: UITextField) {
    if ( textField == pwdTextField || textField == pwd2TextField ) {
        textField.keyboardType = .numberPad;
    }
    // do other stuffs
}

@.@