旋转 CGPDF 文档/页面
我正在加载 CGPDFDocument,将其作为子层添加到 UIView (myContentView),然后将 myContentView 添加到 UIScrollView。效果很好。现在我想允许用户旋转 PDF(如果他们选择)。让 PDF 最初通过一些旋转显示很容易 - 我只是在这里这样做:
- (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);
}
但是,在初始加载后我该如何做呢?
注意:我尝试过旋转 myContentView,这似乎有效,但完成后,我无法再缩放/取消缩放 PDF...我认为我需要的是强制使用新值再次调用 drawLayer在“旋转”中......我该怎么做?
谢谢, 史蒂夫
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要表明图层需要重绘,请向其发送
setNeedsDisplay
或setNeedsDisplayInRect:
消息。您必须将所需的旋转角度存储在 ivar/property 中,并从drawLayer:inContext:
访问该值。To signal that the layer needs to be redrawn, send it a
setNeedsDisplay
orsetNeedsDisplayInRect:
message. You have to store the desired rotation angle in an ivar/property and access that value fromdrawLayer:inContext:
.尝试在您的图层上调用 setNeedsDisplay
try calling setNeedsDisplay on your layer