From 7d123afe79ae3b5e9a6e8f1171136c384595137f Mon Sep 17 00:00:00 2001 From: fish Date: Sat, 18 Jul 2026 21:32:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=8B=BC=E5=86=99=E9=A1=B5?= =?UTF-8?q?=E9=97=AA=E9=80=80=EF=BC=9A=E6=94=B9=E7=94=A8=20becomeFirstResp?= =?UTF-8?q?onder=20=E7=AE=A1=E7=90=86=E7=84=A6=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.7 --- .../LearnEnglish/Views/SpellingWordInput.swift | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/LearnEnglish/LearnEnglish/Views/SpellingWordInput.swift b/LearnEnglish/LearnEnglish/Views/SpellingWordInput.swift index d969081..e257822 100644 --- a/LearnEnglish/LearnEnglish/Views/SpellingWordInput.swift +++ b/LearnEnglish/LearnEnglish/Views/SpellingWordInput.swift @@ -5,6 +5,7 @@ import UIKit struct KeystrokeCaptureField: UIViewRepresentable { let onChar: (Character) -> Void let onBackspace: () -> Void + @Binding var isActive: Bool func makeUIView(context: Context) -> UITextField { let tf = UITextField() @@ -19,7 +20,13 @@ struct KeystrokeCaptureField: UIViewRepresentable { Coordinator(onChar: onChar, onBackspace: onBackspace) } - func updateUIView(_ uiView: UITextField, context: Context) {} + func updateUIView(_ uiView: UITextField, context: Context) { + if isActive { + uiView.becomeFirstResponder() + } else { + uiView.resignFirstResponder() + } + } class Coordinator: NSObject, UITextFieldDelegate { let onChar: (Character) -> Void @@ -61,7 +68,7 @@ struct SpellingWordInput: View { let blankPositions: [Int] @Binding var currentBlankIndex: Int @Binding var filledBlanks: [String] - @FocusState private var isFocused + @State private var isFocused = false private let chars: [String] @@ -85,11 +92,10 @@ struct SpellingWordInput: View { guard currentBlankIndex > 0 else { return } currentBlankIndex -= 1 filledBlanks[currentBlankIndex] = "" - } + }, + isActive: $isFocused ) .frame(width: 0, height: 0) - .opacity(0.01) - .focused($isFocused) HStack(spacing: 4) { ForEach(Array(chars.enumerated()), id: \.offset) { index, ch in