[已更新]我正在尝试为PDFView
设置pageOverlayViewProvider
,但它无法按预期工作。未调用PDFPageOverlayViewProvider
方法,PDFViewDelegate
方法工作正常。
struct ReaderView: UIViewRepresentable {
public typealias UIViewType = PDFView
let url: URL
let document: PDFDocument
init(_ url: URL) {
self.url = url
self.document = PDFDocument(url: self.url)!
}
func makeCoordinator() -> Coordinator {
Coordinator()
}
func makeUIView(context: Context) -> PDFView {
let pdfView = PDFView()
pdfView.document = document
pdfView.displayMode = .singlePageContinuous
pdfView.displayDirection = .vertical
pdfView.autoScales = true
pdfView.delegate = context.coordinator
pdfView.pageOverlayViewProvider = context.coordinator
pdfView.usePageViewController(true)
pdfView.backgroundColor = .clear
document.delegate = context.coordinator
return pdfView
}
func updateUIView(_ uiView: PDFView, context: Context) {
}
}
extension ReaderView {
class Coordinator: NSObject, PDFPageOverlayViewProvider, PDFViewDelegate, PDFDocumentDelegate {
func pdfView(_ view: PDFView, overlayViewFor page: PDFPage) -> UIView? {
return UIView(frame: .zero)
}
func pdfView(_ pdfView: PDFView, willDisplayOverlayView overlayView: UIView, for page: PDFPage) {
}
func pdfView(_ pdfView: PDFView, willEndDisplayingOverlayView overlayView: UIView, for page: PDFPage) {
}
func pdfViewWillClick(onLink sender: PDFView, with url: URL) {
}
func didMatchString(_ instance: PDFSelection) {
}
}
2条答案
按热度按时间rekjcdws1#
要让
pageOverlayViewProvider
与PDFView
一起工作,似乎必须在将PDF文档与PDFView
关联之前 * 设置此示例属性。在使用
UIViewRepresentable
时,在使用makeUIView
函数制作PDFView
时,以下应该可以工作:mnemlml82#
我也遇到过这个问题,基于omar的回答,我在
PDFView
子类中添加了以下内容: