开发者

Rotate CGPDFDocument/Page

开发者 https://www.devze.com 2023-02-14 22:47 出处:网络
I\'m loading a CGPDFDocument, adding that as a sublayer to a UIView (myContentView), and then adding myContentView to a UIScrollView.That works fine.Now I want to allow the user to rotate the PDF if t

I'm loading a CGPDFDocument, adding that as a sublayer to a UIView (myContentView), and then adding myContentView to a UIScrollView. That works fine. Now I want to allow the user to rotate the PDF if they choose to. It's easy to get the PDF to initially display with some rotation- I just do it here:

- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx {
    CGContextSaveGState (ctx);
    CGContextSetRGBFillColor(ctx, 1.0, 1.0, 1.0, 1.0);
    CGContextFillRect(ctx, CGContextGetClipBoundingBox(ctx));
    CGContextTranslateCTM(ctx, 0.0, layer.bounds.size.height);
    CGContextScaleCTM(ctx, 1.0, -1.0);
    CGContextConcatCTM(ctx, CGPDFPageGetDrawingTransform(myPageRef, kCGPDFCropBox, layer.bounds, rotation, true));
    CGContextDrawPDFPage(ctx, myPageRef);
    CGContextRestoreGState (ctx);
}

But, how can I do it after the initial load?

Note: I've tried just rotating myContentView, which seems like it works, but after doing it, I can no longer zoom/unzoom the PDF... I think what I need is to force drawLayer to be calle开发者_开发知识库d again with a new value in "rotation"... how do I do that?

Thanks, Steve


To signal that the layer needs to be redrawn, send it a setNeedsDisplay or setNeedsDisplayInRect: message. You have to store the desired rotation angle in an ivar/property and access that value from drawLayer:inContext:.


try calling setNeedsDisplay on your layer

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号