我使用下面的代码在pdfpage上画了一条线。当用户将其拖到上方时,有什么办法可以像橡皮擦一样擦除该注释。

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)

最佳答案

1)将平移手势识别器添加到您的PDFView

2)跟踪手势,并在适当的时候(例如手势越过注释)调用page.removeAnnotation(lineAnnotation)
这就是从手势识别器获取页面内触摸位置的方法

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];

07-26 09:37