swift pdf.document 的滚动位置
swift scroll position of pdf.document
我在使用 PDFKit 的 pdfView 中有一个 pdf 文档
var urldocs = getDocumentsDirectoryURL()
urldocs.appendPathComponent("test.pdf")
let pdfDocument = PDFDocument(url: urldocs)
pdfView.displayMode = .singlePageContinuous
pdfView.autoScales = true
pdfView.document = pdfDocument
如何设置 pdfView 以显示嵌入文档的特定区域!?
在 ScrollView 中,可以 ScrollView.contentOffset = CGPoint...
我不知道如何在 pdfView
中执行此操作
谢谢!
您可以转到通过文档中的文本搜索找到的选择:
let selections = pdfView.document!.findString("have a pdf document", withOptions: [NSString.CompareOptions.literal])
guard let newSelection = selections.first else {
fatalError("selection not found.")
}
update(pdfView) {
[=10=].setCurrentSelection(newSelection, animate: true)
[=10=].scrollSelectionToVisible(nil)
}
或者您可以转到页面上的 cgRect:
let pdfPage = pdfView.document!.page(at: 0)!
pdfView.go(to: cgRect, on: pdfPage)
这将转到第 2 页第 10、10 处的 100x100 大小的区域。由于它是基于 0 的索引,因此第 2 页表示为索引 1。
pdfView.go(to:CGRect(x: 10, y: 10, width: 100, height: 100), on:pdfView.document.page(at: 1))
我在使用 PDFKit 的 pdfView 中有一个 pdf 文档
var urldocs = getDocumentsDirectoryURL()
urldocs.appendPathComponent("test.pdf")
let pdfDocument = PDFDocument(url: urldocs)
pdfView.displayMode = .singlePageContinuous
pdfView.autoScales = true
pdfView.document = pdfDocument
如何设置 pdfView 以显示嵌入文档的特定区域!? 在 ScrollView 中,可以 ScrollView.contentOffset = CGPoint... 我不知道如何在 pdfView
中执行此操作谢谢!
您可以转到通过文档中的文本搜索找到的选择:
let selections = pdfView.document!.findString("have a pdf document", withOptions: [NSString.CompareOptions.literal])
guard let newSelection = selections.first else {
fatalError("selection not found.")
}
update(pdfView) {
[=10=].setCurrentSelection(newSelection, animate: true)
[=10=].scrollSelectionToVisible(nil)
}
或者您可以转到页面上的 cgRect:
let pdfPage = pdfView.document!.page(at: 0)!
pdfView.go(to: cgRect, on: pdfPage)
这将转到第 2 页第 10、10 处的 100x100 大小的区域。由于它是基于 0 的索引,因此第 2 页表示为索引 1。
pdfView.go(to:CGRect(x: 10, y: 10, width: 100, height: 100), on:pdfView.document.page(at: 1))