隐藏 PDF Demo 阅读器中的 AI 助手入口与 TTS 朗读控件
PDF Demo 宿主在阅读界面右上角常驻一个 "AI" 按钮,底部常驻一组 TTS 播放 控件。这两处是示例性质的能力入口,当前不希望在阅读界面上出现。 在宿主控制器上引入 showsAIAssistant 与 showsSpeechControls 两个开关, viewDidLoad 中据此决定是否创建 AI 按钮、是否装配朗读控件,两者都不再被 加入视图层级。底层的 presentAIAssistant、speechSession 及播放、语速控制 逻辑全部保留,把开关置为 true 即可恢复,避免以后重新接入时再写一遍。 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -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)])
|
||||
|
||||
Reference in New Issue
Block a user