问题
I code an iOS App in Swift 4, I'm french so I work with mobile phone in french language/french region.
With an iOS 12 device, my password field on my login page works perfectly fine (the auto-login with saved password even works and I didn't do anything to get this working), but on my register page, the field makes my keyboard switch from AZERTY to QWERTY.
There is just the AZERTY keyboard in my phone settings, and it happens with all the iOS 12 devices not just mine...
The only thing I do in code : (my UIView file is named RegisterView.swift)
fieldPwd = UITextField()
fieldPwdConfirm = UITextField()
fieldPwd.isSecureTextEntry = true
fieldPwdConfirm.isSecureTextEntry = true
Is there any fix to this issue ? Thanks !
回答1:
I've found a solution for my project, maybe it can help someone.
I've noticed that :
- 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
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.
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
}
@.@
来源:https://stackoverflow.com/questions/53004048/password-fields-keyboard-switches-from-azerty-to-qwerty-sometimes-only-on-ios