CALayer 和离屏渲染
我有一个 Paging UIScrollView
,其 contentSize 足够大,可以容纳许多用于缩放的小型 UIScrollView,viewForZoomingInScrollView
是一个 viewController,它容纳一个用于在其上绘制 PDF 页面的 CALayer。这使我能够像 ibooks PDF 阅读器一样浏览 PDF。
绘制 PDF(平铺图层)的代码位于:
- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx;
并且只需将“页面”添加到可见屏幕即可自动调用此方法。当我更改页面时,即使已经创建了对象(页面),在绘制所有图块之前也会有一些延迟。
我想要做的是在用户滚动到下一页之前渲染下一页,从而防止可见的平铺效果。但是,我发现如果图层位于屏幕外,将其添加到滚动视图不会调用drawLayer
。
这里有什么想法/常见问题吗?
我已经尝试过:
[viewController.view.layer setNeedsLayout];
[viewController.view.layer setNeedsDisplay];
注意:在功能上复制 ibook 的事实与完整应用程序的上下文无关。
I have a Paging UIScrollView
with a contentSize large enough to hold a number of small UIScrollViews for zooming, The viewForZoomingInScrollView
is a viewController that holds a CALayer for drawing a PDF page onto. This allows me to navigate through a PDF much like the ibooks PDF reader.
The code that draws the PDF (Tiled Layers) is located in:
- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx;
And simply adding a 'page' to the visible screen calls this method automatically. When I change page there is some delay before all the tiles are drawn, even though the object (page) has already been created.
What i want to be able to do is render the next page before the user scrolls to it, thus preventing the visible tiling effect. However, i have found that if the layer is located offscreen adding it to the scrollview doesn't call the drawLayer
.
Any Ideas/common gotchas here?
I have tried:
[viewController.view.layer setNeedsLayout];
[viewController.view.layer setNeedsDisplay];
NB: The fact that this is replicating the ibooks functionally is irrelevant within the context of the full app.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如我上面提到的,如果 CALayers 位于屏幕外,则它们不会渲染。
我最终没有将 PDF 直接绘制到图层上,而是在需要时将 PDF 页面渲染为图像(渲染 1 页加上和减去焦点页面之一)
以下是渲染代码:
As i mentioned above, CALayers don't render if they are offscreen.
I ended up not drawing the PDF directly to the layer but instead, rendered the PDF page to an image when i needed (renders 1 page plus and minus one of the focused page)
Here is the render code: