擦除pdfAnnotation使用pdfkit添加

问题描述 投票:2回答:1

我用下面的代码来画一条线到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)
ios swift pdfkit pdf-annotations pdfpage
1个回答
0
投票

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];
© www.soinside.com 2019 - 2024. All rights reserved.