func textFieldDidBeginEditing(textField: UITextField) {
scrlView.setContentOffset(CGPointMake(0, textField.frame.origin.y-70), animated: true)
if(textField == firstDigit){
textField.becomeFirstResponder()
secondDigit.resignFirstResponder()
}
else if(textField == secondDigit){
textField.becomeFirstResponder()
thirdDigit.resignFirstResponder()
}
else if(textField == thirdDigit){
//textField.becomeFirstResponder()
fourthDigit.becomeFirstResponder()
}
Run Code Online (Sandbox Code Playgroud)
我使用四个文本字段进行OTP输入,其中一次只能输入一个数字.输入数字后,我需要将光标自动移动到下一个文本字段.
React Native 如何从移动短信中自动获取文本字段中的 OTP,是否应同时支持 ios 和 android?
我正在为内置于react-native的移动应用程序进行登录过程... https://files.slack.com/files-pri/T039NS2ED-FHARU61LH/image_from_ios.jpg
我想使用某种“发件人选项卡”来自动填写我的密码。我想知道是否有人知道什么可以引导我朝正确的方向前进。
有没有办法通过限制其他键盘输入来处理一次性代码敲击?
我需要 OTP 文本字段来预填充短信 OTP 代码。用户不应使用键盘数字按钮手动输入 OTP。
iOS 12 我们有一次性代码选项,它将自动填充在 QuickType 栏中,用户可以点击它来填充文本字段。我找不到限制其他键盘输入的选项。
有什么方法可以让我们只允许一次性代码点击并限制从数字键盘输入任何内容。
我尝试过创建 6 个文本字段。第一个文本字段内容类型设置为一次性代码。UserInteractionEnabled 仅适用于第一个文本字段,以便用户无法在其他字段中输入数据。一旦我获得 OTP 并点击 QuickType 栏 - 一次性代码,我就会预填写所有文本字段。
查看已加载>
otp1TB.addTarget(self, action:#selector(textFieldDidChange(_:)), for: .editingChanged)
@objc func textFieldDidChange(_ textField: UITextField) {
if let otpCode = textField.text , otpCode.count > 5 {
otp1TB.text = String(otpCode[otpCode.startIndex])
otp2TB.text = String(otpCode[otpCode.index(otpCode.startIndex, offsetBy: 1)])
otp3TB.text = String(otpCode[otpCode.index(otpCode.startIndex, offsetBy: 2)])
otp4TB.text = String(otpCode[otpCode.index(otpCode.startIndex, offsetBy: 3)])
otp5TB.text = String(otpCode[otpCode.index(otpCode.startIndex, offsetBy: 4)])
otp6TB.text = String(otpCode[otpCode.index(otpCode.startIndex, offsetBy: 5)])
otp1TB.isUserInteractionEnabled = false
self.view.endEditing(true)
}
}
Run Code Online (Sandbox Code Playgroud)
这里的问题是,因为当键盘打开时第一个文本字段处于活动状态,用户可以从键盘输入数字数据。 …
对于 OTP 文本字段,我已将 textContentType 设置为 oneTimeCode
if #available(iOS 12.0, *) {
otpTextField.textContentType = .oneTimeCode
}
Run Code Online (Sandbox Code Playgroud)
现在,当我们收到 OTP 时,iOS 会为所有键盘类型设置为数字键盘的文本字段显示 OTP,例如)安全令牌、邮政编码等。
应用程序应该只为 textContentType 为 oneTimeCode 的文本字段填充 OTP,而不是应用程序中的所有文本字段。
如何为特定文本字段启用/禁用 oneTimeCode?