0

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 called again with a new value in "rotation"... how do I do that?

Thanks, Steve

FreeAsInBeer
  • 12,937
  • 5
  • 50
  • 82
Steve N
  • 2,667
  • 3
  • 30
  • 37

2 Answers2

0

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:.

Ole Begemann
  • 135,006
  • 31
  • 278
  • 256
  • Still nothing. I've tried a few ways: saving a ref to the CATiledLayer as an ivar, then calling setNeedsDisplay on that.. also tried accessing the CALayer through scrollView.subviews[0].sublayers[0] and calling setNeedsDisplay on that.. neither have worked. I am storing rotation as an ivar so it updates properly each time. Breakpoints set in drawLayer aren't called. – Steve N Mar 06 '11 at 16:48
  • Based on some Googling, I'm beginning to suspect this my be an iOS SDK 4.x bug. – Steve N Mar 10 '11 at 14:55
0

try calling setNeedsDisplay on your layer

Mike Bluestein
  • 706
  • 3
  • 7