我正在开发一个 pdf 注释应用程序,到目前为止,我可以使用“PDFAnnotationSubtype.stamp”中的图像画一条线。
使用下面的代码:
public class ImageAnnotation: PDFAnnotation{
init(with image: UIImage!, forBounds bounds: CGRect, withProperties properties: [AnyHashable : Any]?) {
super.init(bounds: bounds, forType: PDFAnnotationSubtype.stamp, withProperties: properties)
self._image = image
}
override public func draw(with box: PDFDisplayBox, in context: CGContext) {
guard let cgImage = self._image?.cgImage else { return }
context.draw(cgImage, in: self.bounds)
}
}
使用这种方法,我最终在每个 CGpoint 添加图像(换句话说,每个 cgpoint 都是单独的 PDFAnnotation)。如何将整个路径制作为单个笔划/单个注释,这样当我尝试擦除时,应该清除整个路径而不是只有几个 cgpoint/像素。