From e176a83b6120afe6360becfb139ac55ac2f026a8 Mon Sep 17 00:00:00 2001 From: fish Date: Tue, 21 Jul 2026 21:11:45 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8B=BC=E5=86=99=E5=AD=A6=E4=B9=A0=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F=E6=94=B9=E7=94=A8=E9=94=AE=E7=9B=98=E5=AE=8C=E6=88=90?= =?UTF-8?q?=E9=94=AE=E6=8F=90=E4=BA=A4=EF=BC=8C=E7=A7=BB=E9=99=A4=E7=8E=BB?= =?UTF-8?q?=E7=92=83=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.7 --- .../Views/QuizViewController.swift | 7 --- .../Views/SpellingInputView.swift | 43 +++---------------- 2 files changed, 7 insertions(+), 43 deletions(-) diff --git a/LearnEnglish/LearnEnglish/Views/QuizViewController.swift b/LearnEnglish/LearnEnglish/Views/QuizViewController.swift index 1d96773..341de60 100644 --- a/LearnEnglish/LearnEnglish/Views/QuizViewController.swift +++ b/LearnEnglish/LearnEnglish/Views/QuizViewController.swift @@ -221,13 +221,7 @@ final class QuizViewController: UIViewController { spellingView.configure(blankedWord: question.blankedWord, blankPositions: question.blankPositions) if config.isStudyMode { nextButton.isHidden = true - spellingView.onChange = { [weak self] in - guard let self else { return } - spellingView.confirmButton?.isEnabled = spellingView.isComplete - } - spellingView.confirmButton?.isEnabled = false } else { - spellingView.hideAccessoryView() spellingView.onChange = { [weak self] in guard let self else { return } nextButton.isEnabled = spellingView.isComplete @@ -238,7 +232,6 @@ final class QuizViewController: UIViewController { } spellingView.onSubmit = { [weak self] in guard let self else { return } - spellingView.confirmButton?.isEnabled = false primaryButtonTapped() } spellingView.activate() diff --git a/LearnEnglish/LearnEnglish/Views/SpellingInputView.swift b/LearnEnglish/LearnEnglish/Views/SpellingInputView.swift index e7691e8..f0965e1 100644 --- a/LearnEnglish/LearnEnglish/Views/SpellingInputView.swift +++ b/LearnEnglish/LearnEnglish/Views/SpellingInputView.swift @@ -3,7 +3,6 @@ import UIKit final class SpellingInputView: UIView, UITextFieldDelegate { var onChange: (() -> Void)? var onSubmit: (() -> Void)? - private(set) var confirmButton: UIButton? private let hiddenField = UITextField() private let stack = UIStackView() @@ -55,39 +54,10 @@ final class SpellingInputView: UIView, UITextFieldDelegate { hiddenField.autocapitalizationType = .none hiddenField.spellCheckingType = .no hiddenField.keyboardType = .asciiCapable + hiddenField.returnKeyType = .done hiddenField.frame = .zero addSubview(hiddenField) - let accessory = UIView() - accessory.frame = CGRect(x: 0, y: 0, width: 0, height: 74) - accessory.autoresizingMask = .flexibleWidth - accessory.backgroundColor = .clear - - var glassConfig = UIButton.Configuration.glass() - glassConfig.title = "确认" - glassConfig.cornerStyle = .fixed - glassConfig.background.cornerRadius = 25 - glassConfig.baseForegroundColor = .label - glassConfig.titleTextAttributesTransformer = UIConfigurationTextAttributesTransformer { incoming in - var outgoing = incoming - outgoing.font = .systemFont(ofSize: 16, weight: .semibold) - return outgoing - } - let glassButton = UIButton(configuration: glassConfig) - confirmButton = glassButton - glassButton.addAction(UIAction { [weak self] _ in - self?.onSubmit?() - }, for: .touchUpInside) - glassButton.translatesAutoresizingMaskIntoConstraints = false - accessory.addSubview(glassButton) - NSLayoutConstraint.activate([ - glassButton.trailingAnchor.constraint(equalTo: accessory.trailingAnchor, constant: -15), - glassButton.topAnchor.constraint(equalTo: accessory.topAnchor, constant: 12), - glassButton.widthAnchor.constraint(equalToConstant: 80), - glassButton.heightAnchor.constraint(equalToConstant: 50) - ]) - hiddenField.inputAccessoryView = accessory - addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(reactivate))) } @@ -127,11 +97,6 @@ final class SpellingInputView: UIView, UITextFieldDelegate { refreshBoxes() } - func hideAccessoryView() { - confirmButton?.isHidden = true - hiddenField.inputAccessoryView = nil - } - func showResultState(correct: Bool) { let color = correct ? Theme.Color.correct : Theme.Color.wrong for position in blankPositions { @@ -178,6 +143,12 @@ final class SpellingInputView: UIView, UITextFieldDelegate { return false } + func textFieldShouldReturn(_ textField: UITextField) -> Bool { + guard isComplete else { return false } + onSubmit?() + return false + } + // MARK: - Boxes private func rebuildBoxes() {