I'm working with PDFKit and trying to rotate PDFAnnotation from a PDFView:
Here is my code for a normal case(no rotated):
class ImageAnnotation: PDFAnnotation {
var image: UIImage?
init(image: UIImage?, bounds: CGRect) {
self.image = image
super.init(bounds: bounds, forType: .stamp, withProperties: nil)
}
override func draw(with box: PDFDisplayBox, in context: CGContext) {
guard let cgImage = self.image?.cgImage else { return }
context.draw(cgImage, in: bound)
}
}
And here is the way I used to rotate PDFAnnotation:
init(image: UIImage?, bounds: CGRect) {
self.image = image
super.init(bounds: bounds.applying(CGAffineTransform(rotationAngle: -CGFloat.pi/12)), forType: .stamp, withProperties: nil)
}
override func draw(with box: PDFDisplayBox, in context: CGContext) {
guard let cgImage = self.image?.cgImage else { return }
context.rotate(by: CGFloat.pi/12)
context.draw(cgImage, in: bounds)
}
But it doesn't work as expected. Can you help me? Thank you.