You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SwiftUI混用SecureField与TextField时键盘闪烁、屏幕跳动问题

iOS17下TextField搭配SecureField出现界面闪烁跳动问题

以下代码仅使用两个TextField时可正常运行:

struct TestView: View {
    @State private var email = ""
    @State private var password = ""

    var body: some View {
        VStack{
            TextField("Enter your email", text: $email)
                .font(.subheadline)
                .padding(12)
                .background(Color(.systemGray6))
                .cornerRadius(10)
                .padding(.horizontal, 24)
            
            TextField("Enter your password", text: $password)
                .font(.subheadline)
                .padding(12)
                .background(Color(.systemGray6))
                .cornerRadius(10)
                .padding(.horizontal, 24)
        }
    }
}

将第二个密码输入框替换为SecureField后,界面出现异常,表现为屏幕和键盘闪烁、跳动:

struct TestView: View {
    @State private var email = ""
    @State private var password = ""

    var body: some View {
        VStack{
            TextField("Enter your email", text: $email)
                .font(.subheadline)
                .padding(12)
                .background(Color(.systemGray6))
                .cornerRadius(10)
                .padding(.horizontal, 24)
            
            SecureField("Enter your password", text: $password)
                .font(.subheadline)
                .padding(12)
                .background(Color(.systemGray6))
                .cornerRadius(10)
                .padding(.horizontal, 24)
        }
    }
}

测试环境:iOS17系统,已在模拟器和iPhone 13 Pro Max真机上验证,真机上异常表现更为明显,模拟器中也可观测到。目前不确定该问题是代码错误导致,还是系统存在Bug。

内容的提问来源于stack exchange,提问作者xen555

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 02:16:17