如何在 PDFView Swift 中显示旋转图像 PDFAnnotation?

时间:2021-02-07 05:09:33

标签: ios swift cgcontext pdfkit image-rotation

关于在 PDFView 中显示旋转图像 PDFAnnotation,我需要您的建议。我使用以下内容来显示旋转后的图像 PDFAnnotation。

override func draw(with box: PDFDisplayBox, in context: CGContext) {
            
    let drawingBox = self.page?.bounds(for: box)
    
    UIGraphicsPushContext(context)
    context.saveGState()
    context.translateBy(x: bounds.midX, y: bounds.midY)
    context.rotate(by: 0.7310428063040626)
    context.translateBy(x: -bounds.midX, y: -bounds.midY)
    guard let cgImage = image.cgImage else { return }
   
    context.draw(cgImage, in: self.bounds.applying(CGAffineTransform(
           translationX: (drawingBox?.origin.x)! * -1.0,
                      y: (drawingBox?.origin.y)! * -1.0)))

    context.restoreGState()
    UIGraphicsPopContext()        
}

问题是在 draw 方法中旋转图像时,由于旋转的图像不适合 PDFAnnotation 边界,图像的某些部分被截断。

Cropped Image

我需要您就我们如何解决此问题提出建议。

0 个答案:

没有答案
相关问题