1

it's possible to add GestureRecognizer or set on touch to 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 ------")
}
pch
  • 13
  • 6

2 Answers2

6

Hopefully this method will work for you..

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

  @objc func titleTapped()  {
       -Provide the action you want---
    }
Dmytro Dadyka
  • 2,208
  • 5
  • 18
  • 31
4

It's not possible to add the gesture recognizer to the annotation itself. However you can add it to the PDFView and then check if the user tapped on an annotation. Here's a simple snippet:

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)
}

I hope this helps.

gulyashki
  • 449
  • 3
  • 5