详情页移除入场动画、标题显示分类名,汉选英播放按钮选答后才显示

This commit is contained in:
2026-07-18 23:58:50 +08:00
parent c3a4990984
commit def92715ac
3 changed files with 17 additions and 18 deletions
@@ -28,6 +28,12 @@ final class QuizViewController: UIViewController {
private let promptStack = UIStackView() private let promptStack = UIStackView()
private let inputStack = UIStackView() private let inputStack = UIStackView()
private let resultStack = UIStackView() private let resultStack = UIStackView()
private let navSpeakerItem = UIBarButtonItem(
image: UIImage(systemName: "speaker.wave.2.fill"),
style: .plain,
target: nil,
action: nil
)
private var current: QuizQuestion? { private var current: QuizQuestion? {
questions.indices.contains(currentIndex) ? questions[currentIndex] : nil questions.indices.contains(currentIndex) ? questions[currentIndex] : nil
@@ -110,12 +116,9 @@ final class QuizViewController: UIViewController {
nextButton.configuration = nextConfig nextButton.configuration = nextConfig
nextButton.addAction(UIAction { [weak self] _ in self?.primaryButtonTapped() }, for: .touchUpInside) nextButton.addAction(UIAction { [weak self] _ in self?.primaryButtonTapped() }, for: .touchUpInside)
navigationItem.rightBarButtonItem = UIBarButtonItem( navSpeakerItem.target = self
image: UIImage(systemName: "speaker.wave.2.fill"), navSpeakerItem.action = #selector(speakCurrentWord)
style: .plain, navigationItem.rightBarButtonItem = navSpeakerItem
target: self,
action: #selector(speakCurrentWord)
)
let headerStack = UIStackView(arrangedSubviews: [progressView, countLabel]) let headerStack = UIStackView(arrangedSubviews: [progressView, countLabel])
headerStack.axis = .vertical headerStack.axis = .vertical
@@ -163,6 +166,8 @@ final class QuizViewController: UIViewController {
resultLabel.isHidden = true resultLabel.isHidden = true
resultPhoneticLabel.isHidden = true resultPhoneticLabel.isHidden = true
navigationItem.rightBarButtonItem = config.mode == .zhToEn ? nil : navSpeakerItem
let isSpelling = config.mode == .spelling let isSpelling = config.mode == .spelling
let isDictation = config.mode == .dictation let isDictation = config.mode == .dictation
let isChoice = !isSpelling && !isDictation let isChoice = !isSpelling && !isDictation
@@ -290,6 +295,7 @@ final class QuizViewController: UIViewController {
icon.transform = .identity icon.transform = .identity
} }
} }
navigationItem.rightBarButtonItem = navSpeakerItem
showResult(correct, for: question) showResult(correct, for: question)
} }
@@ -2,16 +2,17 @@ import UIKit
final class WordDetailViewController: UIViewController { final class WordDetailViewController: UIViewController {
private let word: Word private let word: Word
private let categoryName: String
private let speech = SpeechService.shared private let speech = SpeechService.shared
private let speakButton = UIButton(type: .system) private let speakButton = UIButton(type: .system)
private let exampleSpeakButton = UIButton(type: .system) private let exampleSpeakButton = UIButton(type: .system)
private let contentStack = UIStackView() private let contentStack = UIStackView()
private var speechObserver: NSObjectProtocol? private var speechObserver: NSObjectProtocol?
private var didAnimateEntry = false
init(word: Word) { init(word: Word, categoryName: String = "") {
self.word = word self.word = word
self.categoryName = categoryName
super.init(nibName: nil, bundle: nil) super.init(nibName: nil, bundle: nil)
} }
@@ -27,7 +28,7 @@ final class WordDetailViewController: UIViewController {
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
view.backgroundColor = .systemBackground view.backgroundColor = .systemBackground
title = word.word title = categoryName
navigationItem.largeTitleDisplayMode = .never navigationItem.largeTitleDisplayMode = .never
buildLayout() buildLayout()
updateSpeakState() updateSpeakState()
@@ -38,14 +39,6 @@ final class WordDetailViewController: UIViewController {
} }
} }
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
if !didAnimateEntry {
didAnimateEntry = true
contentStack.animateEntry(distance: 16, duration: 0.35)
}
}
private func updateSpeakState() { private func updateSpeakState() {
let wordSpeaking = speech.isSpeaking(word.word) let wordSpeaking = speech.isSpeaking(word.word)
speakButton.configuration?.image = UIImage( speakButton.configuration?.image = UIImage(
@@ -148,6 +148,6 @@ extension WordListViewController: UITableViewDataSource, UITableViewDelegate {
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
Haptics.selection() Haptics.selection()
navigationController?.pushViewController( navigationController?.pushViewController(
WordDetailViewController(word: category.words[indexPath.row]), animated: true) WordDetailViewController(word: category.words[indexPath.row], categoryName: category.name), animated: true)
} }
} }