无法从PDFView获得选择

时间:2019-07-10 14:03:45

标签: swift ios-pdfkit apple-pdfkit

我在此代码的某处看到了突出显示pdf文档中所选文本的代码:

let select = pdfView.currentSelection?.selectionsByLine()
    //assuming for single-page pdf.
    guard let page = select?.first?.pages.first else { return }

    select?.forEach({ selection in
        let highlight = PDFAnnotation(bounds: select.bounds(for: page), forType: .highlight, withProperties: nil)
        highlight.endLineStyle = .square
        highlight.color = UIColor.orange.withAlphaComponent(0.5)

        page.addAnnotation(highlight)
    })

对我来说,

让select = pdfView.currentSelection?.selectionsByLine()

始终为零。将此代码放在哪里。我将其放入“手势识别器代理”方法中。

也似乎在页面上添加了多个注释。我们在页面上的每个选择都得到单个高亮注释吗?

0 个答案:

没有答案