From 735c14c824e0eb327273e3d765b27675b5103e47 Mon Sep 17 00:00:00 2001 From: shenlei Date: Thu, 30 Jul 2026 17:51:57 +0900 Subject: [PATCH] =?UTF-8?q?=E9=9A=90=E8=97=8F=20PDF=20Demo=20=E9=98=85?= =?UTF-8?q?=E8=AF=BB=E5=99=A8=E4=B8=AD=E7=9A=84=20AI=20=E5=8A=A9=E6=89=8B?= =?UTF-8?q?=E5=85=A5=E5=8F=A3=E4=B8=8E=20TTS=20=E6=9C=97=E8=AF=BB=E6=8E=A7?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PDF Demo 宿主在阅读界面右上角常驻一个 "AI" 按钮,底部常驻一组 TTS 播放 控件。这两处是示例性质的能力入口,当前不希望在阅读界面上出现。 在宿主控制器上引入 showsAIAssistant 与 showsSpeechControls 两个开关, viewDidLoad 中据此决定是否创建 AI 按钮、是否装配朗读控件,两者都不再被 加入视图层级。底层的 presentAIAssistant、speechSession 及播放、语速控制 逻辑全部保留,把开关置为 true 即可恢复,避免以后重新接入时再写一遍。 Co-Authored-By: Claude Opus 5 --- .../PDFDemoReaderViewController.swift | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/ReadViewDemo/ReadViewDemo/PDFDemoReaderViewController.swift b/ReadViewDemo/ReadViewDemo/PDFDemoReaderViewController.swift index 1097632..055cd38 100644 --- a/ReadViewDemo/ReadViewDemo/PDFDemoReaderViewController.swift +++ b/ReadViewDemo/ReadViewDemo/PDFDemoReaderViewController.swift @@ -152,6 +152,9 @@ private final class PDFDemoPageProvider: RDPDFReaderPageProvider, RDPDFReaderOut /// 成品阅读器的 Demo 宿主:存储位置、返回导航和自动化状态是唯一的应用职责。 final class PDFDemoReaderViewController: UIViewController, RDPDFReaderViewControllerDelegate { private static let annotationStorageFolderName = "RDPDFImageReaderAnnotations" + /// 暂时隐藏阅读器中的 AI 助手入口与 TTS 朗读控件,实现保留以便随时恢复。 + private static let showsAIAssistant = false + private static let showsSpeechControls = false private let reader: RDPDFReaderViewController private lazy var speechSession: RDPDFSpeechSession = { let session = reader.makeSpeechSession() @@ -224,15 +227,17 @@ final class PDFDemoReaderViewController: UIViewController, RDPDFReaderViewContro reader.view.autoresizingMask = [.flexibleWidth, .flexibleHeight] view.addSubview(reader.view) reader.didMove(toParent: self) - configureSpeechControls() - let assistantButton = UIButton(type: .system) - assistantButton.setTitle("AI", for: .normal) - assistantButton.titleLabel?.font = .preferredFont(forTextStyle: .headline) - assistantButton.addTarget(self, action: #selector(presentAIAssistant), for: .touchUpInside) - assistantButton.accessibilityLabel = "打开阅读助手" - view.addSubview(assistantButton) - assistantButton.translatesAutoresizingMaskIntoConstraints = false - NSLayoutConstraint.activate([assistantButton.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 12), assistantButton.trailingAnchor.constraint(equalTo: view.layoutMarginsGuide.trailingAnchor), assistantButton.widthAnchor.constraint(greaterThanOrEqualToConstant: 44), assistantButton.heightAnchor.constraint(equalToConstant: 44)]) + if Self.showsSpeechControls { configureSpeechControls() } + if Self.showsAIAssistant { + let assistantButton = UIButton(type: .system) + assistantButton.setTitle("AI", for: .normal) + assistantButton.titleLabel?.font = .preferredFont(forTextStyle: .headline) + assistantButton.addTarget(self, action: #selector(presentAIAssistant), for: .touchUpInside) + assistantButton.accessibilityLabel = "打开阅读助手" + view.addSubview(assistantButton) + assistantButton.translatesAutoresizingMaskIntoConstraints = false + NSLayoutConstraint.activate([assistantButton.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 12), assistantButton.trailingAnchor.constraint(equalTo: view.layoutMarginsGuide.trailingAnchor), assistantButton.widthAnchor.constraint(greaterThanOrEqualToConstant: 44), assistantButton.heightAnchor.constraint(equalToConstant: 44)]) + } stateLabel.translatesAutoresizingMaskIntoConstraints = false view.addSubview(stateLabel) NSLayoutConstraint.activate([stateLabel.widthAnchor.constraint(equalToConstant: 1), stateLabel.heightAnchor.constraint(equalToConstant: 1), stateLabel.topAnchor.constraint(equalTo: view.topAnchor), stateLabel.leadingAnchor.constraint(equalTo: view.leadingAnchor)])