当前位置: 代码迷 >> 综合 >> SwiftUI PDFKit如何响应翻页消息
  详细解决方案

SwiftUI PDFKit如何响应翻页消息

热度:84   发布时间:2024-02-07 14:17:36.0

实战需求

SwiftUI PDFKit如何响应翻页消息?

实战代码

class ViewController: NSViewController {@IBOutlet weak var pdfView: PDFView!@IBOutlet weak var textView: NSTextView!override func viewDidLoad() {super.viewDidLoad()self.pdfView.acceptsDraggedFiles = trueobserveNotifications()}private func observeNotifications() {NotificationCenter.default.addObserver(forName: NSNotification.Name.PDFViewPageChanged, object: nil, queue: nil) { (notification) inguard let pdfView = notification.object as? PDFView else { return }if let attributedString = pdfView.currentPage?.attributedString {self.textView.textStorage?.setAttributedString(attributedString)}}}}

代码讲解

处理函数闭包,方便处理

        NotificationCenter.default.addObserver(forName: NSNotification.Name.PDFViewPageChanged, object: nil, queue: nil) { (notification) in }

技术交流

QQ:3365059189
SwiftUI技术交流QQ群:518696470

  相关解决方案