如何为PDFAnnotation ios swift 4添加GestureRecognizer

时间:2018-02-12 09:42:18

标签: swift4 ios11 pdfkit pdf-annotations

可以添加GestureRecognizer或触摸设置PDFAnnotation

  func setDocumentAnnotation() {
    let anotation:PDFAnnotation = PDFAnnotation(bounds: CGRect(x: pointX, y: pointY, width: pointW, height: pointH), forType: .highlight, withProperties: nil)
        anotation.color = .yellow
        anotation.endLineStyle = .circle
        guard let page = pdfView.currentPage else {return}
        page.addAnnotation(anotation)
}


 @objc func annotationTapping(_ sender: UITapGestureRecognizer){
    print("------- annotationTapping ------")
}

2 个答案:

答案 0 :(得分:1)

无法将手势识别器添加到注释本身。但是,您可以将其添加到PDFView,然后检查用户是否点按了注释。这是一个简单的代码段:

let tappedPage = pdfView.page(for: tapLocation, nearest: false)
if let page = tappedPage {
    let tapPageLocation = pdfView.convert(tapLocation, to: page)
    let annotation = page.annotation(at: tapPageLocation)
}

我希望这会有所帮助。

答案 1 :(得分:1)

希望这种方法对您有用。

 NotificationCenter.default.addObserver(self, selector: #selector (titleTapped), name:Notification.Name.PDFViewAnnotationHit , object: nil)

  @objc func titleTapped()  {
       -Provide the action you want---
    }