我正在为现有的 PDFView 注释图像。这是我目前的状态:
一句话,我想实现:
- 我的图像注释的圆角
- 图像还应该保持我尝试并搜索了许多来源但没有一个有效的原始纵横比。
以下是我当前的代码:
class PDFImageAnnotation: PDFAnnotation {
var image: UIImage?
convenience init(_ image: UIImage?, bounds: CGRect, properties: [AnyHashable : Any]?) {
self.init(bounds: bounds, forType: PDFAnnotationSubtype.stamp, withProperties: properties)
self.image = image
}
override func draw(with box: PDFDisplayBox, in context: CGContext) {
super.draw(with: box, in: context)
// Drawing the image within the annotation's bounds.
guard let cgImage = image?.cgImage else { return }
context.draw(cgImage, in: bounds)
}
}
ViewDidLoad 中的实现:
if let image = pet.picture?.getImage() {
let imageAnnotation = PDFImageAnnotation(image, bounds: CGRect(x: 80, y: 1100, width: 300, height: 300), properties: nil)
pdfView.currentPage?.addAnnotation(imageAnnotation)
}
任何建议都会有所帮助,因为我现在处于死胡同,非常感谢!