拼写学习模式改用键盘完成键提交,移除玻璃按钮
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -221,13 +221,7 @@ final class QuizViewController: UIViewController {
|
|||||||
spellingView.configure(blankedWord: question.blankedWord, blankPositions: question.blankPositions)
|
spellingView.configure(blankedWord: question.blankedWord, blankPositions: question.blankPositions)
|
||||||
if config.isStudyMode {
|
if config.isStudyMode {
|
||||||
nextButton.isHidden = true
|
nextButton.isHidden = true
|
||||||
spellingView.onChange = { [weak self] in
|
|
||||||
guard let self else { return }
|
|
||||||
spellingView.confirmButton?.isEnabled = spellingView.isComplete
|
|
||||||
}
|
|
||||||
spellingView.confirmButton?.isEnabled = false
|
|
||||||
} else {
|
} else {
|
||||||
spellingView.hideAccessoryView()
|
|
||||||
spellingView.onChange = { [weak self] in
|
spellingView.onChange = { [weak self] in
|
||||||
guard let self else { return }
|
guard let self else { return }
|
||||||
nextButton.isEnabled = spellingView.isComplete
|
nextButton.isEnabled = spellingView.isComplete
|
||||||
@@ -238,7 +232,6 @@ final class QuizViewController: UIViewController {
|
|||||||
}
|
}
|
||||||
spellingView.onSubmit = { [weak self] in
|
spellingView.onSubmit = { [weak self] in
|
||||||
guard let self else { return }
|
guard let self else { return }
|
||||||
spellingView.confirmButton?.isEnabled = false
|
|
||||||
primaryButtonTapped()
|
primaryButtonTapped()
|
||||||
}
|
}
|
||||||
spellingView.activate()
|
spellingView.activate()
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import UIKit
|
|||||||
final class SpellingInputView: UIView, UITextFieldDelegate {
|
final class SpellingInputView: UIView, UITextFieldDelegate {
|
||||||
var onChange: (() -> Void)?
|
var onChange: (() -> Void)?
|
||||||
var onSubmit: (() -> Void)?
|
var onSubmit: (() -> Void)?
|
||||||
private(set) var confirmButton: UIButton?
|
|
||||||
|
|
||||||
private let hiddenField = UITextField()
|
private let hiddenField = UITextField()
|
||||||
private let stack = UIStackView()
|
private let stack = UIStackView()
|
||||||
@@ -55,39 +54,10 @@ final class SpellingInputView: UIView, UITextFieldDelegate {
|
|||||||
hiddenField.autocapitalizationType = .none
|
hiddenField.autocapitalizationType = .none
|
||||||
hiddenField.spellCheckingType = .no
|
hiddenField.spellCheckingType = .no
|
||||||
hiddenField.keyboardType = .asciiCapable
|
hiddenField.keyboardType = .asciiCapable
|
||||||
|
hiddenField.returnKeyType = .done
|
||||||
hiddenField.frame = .zero
|
hiddenField.frame = .zero
|
||||||
addSubview(hiddenField)
|
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)))
|
addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(reactivate)))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,11 +97,6 @@ final class SpellingInputView: UIView, UITextFieldDelegate {
|
|||||||
refreshBoxes()
|
refreshBoxes()
|
||||||
}
|
}
|
||||||
|
|
||||||
func hideAccessoryView() {
|
|
||||||
confirmButton?.isHidden = true
|
|
||||||
hiddenField.inputAccessoryView = nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func showResultState(correct: Bool) {
|
func showResultState(correct: Bool) {
|
||||||
let color = correct ? Theme.Color.correct : Theme.Color.wrong
|
let color = correct ? Theme.Color.correct : Theme.Color.wrong
|
||||||
for position in blankPositions {
|
for position in blankPositions {
|
||||||
@@ -178,6 +143,12 @@ final class SpellingInputView: UIView, UITextFieldDelegate {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
|
||||||
|
guard isComplete else { return false }
|
||||||
|
onSubmit?()
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - Boxes
|
// MARK: - Boxes
|
||||||
|
|
||||||
private func rebuildBoxes() {
|
private func rebuildBoxes() {
|
||||||
|
|||||||
Reference in New Issue
Block a user