在 SwiftUI 视图中在 TextField 后面使用多个 SecureField 时的奇怪行为 [英] Odd behavior when using multiple SecureFields following a TextField in a SwiftUI view

查看:22
本文介绍了在 SwiftUI 视图中在 TextField 后面使用多个 SecureField 时的奇怪行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注意:此错误已在 Xcode 13.0 beta 3 中修复

Note: This bug has been fixed in Xcode 13.0 beta 3

在视图中跟随 TextField 时尝试使用多个 SecureField 时,我遇到了非常奇怪的行为.尝试在其中一个 SecureField 中输入文本在一个字符处停止,该字段变为黄色并显示强密码",并在第二个 SecureField 中重复.这发生在 iOS 14.2 的 Xcode 12.2 中的 Xcode 预览版和模拟器中.

I am experiencing very odd behavior when trying to use multiple SecureFields when following a TextField in a view. Attempting to enter text in one of the SecureFields stops at one character with the field turning yellow and displaying "Strong Password", as well as duplicating in the second SecureField. This is occurring on iOS 14.2 in Xcode 12.2 on the Xcode preview and in the simulator.

这是一个演示问题的最小示例:

Here is a minimal example that demonstrates the issue:

struct SecureFieldTestView: View {

    @State var displayName: String = ""
    @State var password = ""
    @State var passwordVerifiation = ""

    var body: some View {
        VStack {
            TextField("Display name", text: $displayName)
            SecureField("Password", text: $password)
            SecureField("Verify Password", text: $passwordVerifiation)

        }
        .padding()
    }
}

struct SecureFieldTestView_Previews: PreviewProvider {
    static var previews: some View {
        SecureFieldTestView()
    }
}

进入模拟器时控制台显示如下错误:

The console shows the following errors when running into the simulator:

[AutoFill] Cannot show Automatic Strong Passwords for app bundleID: <REDACTED BY ME> due to error: iCloud Keychain is disabled
[Assert] View <(null):0x0> does not conform to UITextInput protocol

我尝试将 SecureFields 包装到它们自己的 VStack{} 中并将它们全部包装到一个 Form{} 中,但问题仍然存在.

I have tried to wrap the SecureFields into their own VStack{} and wrapping them all into a Form{}, but the issue remains.

是否有明显我遗漏的东西,或者这是 SDK 中的错误?

Is there something obvious that I am missing or is this a bug in the SDK?

推荐答案

在进一步调查中,出现了另一个问题;软件键盘要经过一些延迟才会出现.在软键盘出现之前在 SecureFields 中输入文本会持续产生问题.等待软键盘出现解决了奇怪的行为.

On further investigation, there is another issue that was occurring; the software keyboard would not appear until after some delay. Entering text in the SecureFields before the software keyboard appeared consistantly produced the issue. Waiting for the software keyboard to appear resolves the odd behavior.

奇怪的是,当设备/模拟器未登录iCloud时,键盘外观的延迟似乎发生了;设备登录时不会出现键盘出现延迟和 SecureField 问题.

Strangely, the delay in the keyboard appearance seems to occur when the device/simulator is not logged into iCloud; the keyboard appearance delay and SecureField issue does not occur when the device is logged in.

这篇关于在 SwiftUI 视图中在 TextField 后面使用多个 SecureField 时的奇怪行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆