3

I used the below code to draw a line to a pdfpage. Is there any way i can erase the annotation like an eraser when user drags over it.

let lineAttributes: [PDFAnnotationKey: Any] = [ .linePoints: [startPoint.x, startPoint.y, point.x, point.y],
            .lineEndingStyles: [PDFAnnotationLineEndingStyle.none,PDFAnnotationLineEndingStyle.none], .color: UIColor.red,.border: PDFBorder() ]
            let lineAnnotation = PDFAnnotation(bounds: pageBounds , forType: .line,withProperties: lineAttributes)
            lineAnnotation.border = border
            lineAnnotation.color = selectedcolor
            page!.addAnnotation(lineAnnotation)
Faheem Rahman
  • 297
  • 2
  • 10

1 Answers1

0

1) add pan gesture recognizer to your PDFView

2) keep track of the gesture and in the right moment (like the gesture goes over the annotation) call page.removeAnnotation(lineAnnotation)

this is how you can get the touch location inside the page from the gesture recognizer

CGPoint touchLocation = [sender locationInView:self.pdfView];
PDFPage * pdfPage = [self.pdfView pageForPoint:touchLocation nearest:NO];
if (pdfPage == nil) {
    return;
}

CGPoint pageLocation = [self.pdfView convertPoint:touchLocation toPage:pdfPage];
Peter Lapisu
  • 18,394
  • 14
  • 107
  • 163