学习模式拼写页面加入刷新倒计时提示
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -21,9 +21,11 @@ final class QuizViewController: UIViewController {
|
|||||||
private let spellingHintLabel = UILabel()
|
private let spellingHintLabel = UILabel()
|
||||||
private let resultLabel = UILabel()
|
private let resultLabel = UILabel()
|
||||||
private let resultPhoneticLabel = UILabel()
|
private let resultPhoneticLabel = UILabel()
|
||||||
|
private let countdownLabel = UILabel()
|
||||||
private let nextButton = UIButton(type: .system)
|
private let nextButton = UIButton(type: .system)
|
||||||
private var optionButtons: [UIButton] = []
|
private var optionButtons: [UIButton] = []
|
||||||
private var optionIcons: [UIImageView] = []
|
private var optionIcons: [UIImageView] = []
|
||||||
|
private var countdownTimer: Timer?
|
||||||
|
|
||||||
private let promptStack = UIStackView()
|
private let promptStack = UIStackView()
|
||||||
private let inputStack = UIStackView()
|
private let inputStack = UIStackView()
|
||||||
@@ -48,6 +50,10 @@ final class QuizViewController: UIViewController {
|
|||||||
@available(*, unavailable)
|
@available(*, unavailable)
|
||||||
required init?(coder: NSCoder) { fatalError() }
|
required init?(coder: NSCoder) { fatalError() }
|
||||||
|
|
||||||
|
deinit {
|
||||||
|
countdownTimer?.invalidate()
|
||||||
|
}
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
view.backgroundColor = .systemBackground
|
view.backgroundColor = .systemBackground
|
||||||
@@ -135,7 +141,11 @@ final class QuizViewController: UIViewController {
|
|||||||
|
|
||||||
resultStack.axis = .vertical
|
resultStack.axis = .vertical
|
||||||
resultStack.spacing = 12
|
resultStack.spacing = 12
|
||||||
[resultLabel, resultPhoneticLabel, nextButton].forEach { resultStack.addArrangedSubview($0) }
|
countdownLabel.font = .preferredFont(forTextStyle: .caption1)
|
||||||
|
countdownLabel.textColor = .tertiaryLabel
|
||||||
|
countdownLabel.textAlignment = .center
|
||||||
|
countdownLabel.isHidden = true
|
||||||
|
[resultLabel, resultPhoneticLabel, countdownLabel, nextButton].forEach { resultStack.addArrangedSubview($0) }
|
||||||
|
|
||||||
let mainStack = UIStackView(arrangedSubviews: [headerStack, promptStack, inputStack, resultStack, UIView()])
|
let mainStack = UIStackView(arrangedSubviews: [headerStack, promptStack, inputStack, resultStack, UIView()])
|
||||||
mainStack.axis = .vertical
|
mainStack.axis = .vertical
|
||||||
@@ -358,6 +368,18 @@ final class QuizViewController: UIViewController {
|
|||||||
if config.isStudyMode {
|
if config.isStudyMode {
|
||||||
nextButton.isHidden = true
|
nextButton.isHidden = true
|
||||||
let delay: TimeInterval = correct ? 1.0 : 3.0
|
let delay: TimeInterval = correct ? 1.0 : 3.0
|
||||||
|
countdownLabel.text = "\(Int(delay)) 秒后继续"
|
||||||
|
countdownLabel.isHidden = false
|
||||||
|
countdownTimer?.invalidate()
|
||||||
|
var remaining = Int(delay)
|
||||||
|
countdownTimer = Timer.scheduledTimer(withTimeInterval: 1, repeats: true) { [weak self] timer in
|
||||||
|
remaining -= 1
|
||||||
|
if remaining > 0 {
|
||||||
|
self?.countdownLabel.text = "\(remaining) 秒后继续"
|
||||||
|
} else {
|
||||||
|
timer.invalidate()
|
||||||
|
}
|
||||||
|
}
|
||||||
DispatchQueue.main.asyncAfter(deadline: .now() + delay) { [weak self] in
|
DispatchQueue.main.asyncAfter(deadline: .now() + delay) { [weak self] in
|
||||||
self?.restart()
|
self?.restart()
|
||||||
}
|
}
|
||||||
@@ -440,6 +462,8 @@ final class QuizViewController: UIViewController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func restart() {
|
private func restart() {
|
||||||
|
countdownTimer?.invalidate()
|
||||||
|
countdownLabel.isHidden = true
|
||||||
view.subviews.compactMap { $0 as? QuizResultView }.forEach { $0.removeFromSuperview() }
|
view.subviews.compactMap { $0 as? QuizResultView }.forEach { $0.removeFromSuperview() }
|
||||||
questions = QuizGenerator.makeQuestions(mode: config.mode, words: config.words)
|
questions = QuizGenerator.makeQuestions(mode: config.mode, words: config.words)
|
||||||
currentIndex = 0
|
currentIndex = 0
|
||||||
|
|||||||
Reference in New Issue
Block a user