ZoomingPDFViewer 苹果示例
我试图理解 Apple 的 ZoomingPDFViewer 示例代码。以下是我对它在我脑海中如何运作的理解中的一些问题。我不太确定我是否理解正确。他们的代码的链接位于:http://developer. apple.com/library/ios/#samplecode/ZoomingPDFViewer/Introduction/Intro.html
(1) CATiledLayer 用于表示不同缩放级别的 PDF。我假设这个类就是用来查看类参考的。除了这个类之外,您还会使用其他东西来实现缩放功能吗?
(2) 在 TiledPDFView 的 initWithFrame 中,它们执行以下操作: tiledLayer.tileSize = CGSizeMake(512.0, 512.0);
tileSize 是构成整个图像的图块吗?如果是这样,为什么尺寸这么大?
(3)oldPDFView和pdfView如何工作?比如在变焦的不同阶段哪一个位于前面,以及它们什么时候被换掉。我很难理解逻辑流程。谢谢。
I'm trying to understand Apple's example code for the ZoomingPDFViewer. Here are some questions that I have in my understanding of how it works in my mind. I'm not really sure if I understand it correctly. The link for their code is at: http://developer.apple.com/library/ios/#samplecode/ZoomingPDFViewer/Introduction/Intro.html
(1) CATiledLayer is used to represent the PDF at different zoom levels. I'm assuming that's what this class is used for looking at the Class Reference. Would you ever use something else besides this class for a zooming function?
(2) in the initWithFrame for TiledPDFView, they do: tiledLayer.tileSize = CGSizeMake(512.0, 512.0);
Is the tileSize the tiles that make up for the whole image? If so, why such a large size?
(3) How does the oldPDFView and pdfView work? Like which one is in front at the different stages of zoom, and when do they get swapped out. I'm having a hard time understanding the flow of the logic. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
(1) 如果您不需要细节级别随不同缩放级别而变化,或者如果 PDF 加载速度足够快以至于不能保证一次绘制几个图块,则带有常规 CALayer 的常规 UIView 就可以正常工作。例如,如果您显示图像而不是 PDF,并且图像加载速度足够快,不会导致性能障碍,则不需要 CATiledLayer 提供的异步加载。如果您想进行比较,PhotoScroller 示例同时使用了平铺和非平铺方法。
(2)tileSize 属性更改图层应分割成的块的大小。您可以将其设置为您想要的任何值。 512x512 实际上并不是那么大,尤其是当您的 PDF 尺寸很大时。默认值为 256x256。
(3) 每当您开始缩放时,oldPDFView 都会被删除并释放。然后将 pdfView 分配给 oldPDFView。当缩放结束时,会根据比例的变化创建一个新的 pdfView,并将其添加到旧的 pdfView 之上。如果新的比例是增加的,则新的 pdfView 将以更高的细节级别进行绘制。这样您就可以越来越深入地放大 PDF。 MaximumZoomScale 和minimumZoomScale 仅限制使用单个手势可以缩放的程度。
(1) If you don't require the level of detail to vary for different zoom levels, or if the PDF loads fast enough to not warrant drawing a couple of tiles at a time, a regular UIView with a regular CALayer will work fine. For instance, if you were displaying an image instead of a PDF, and the image loads fast enough to not cause a performance snag, you would not need the asynchronous loading that CATiledLayer provides. The PhotoScroller sample uses both the tiled and non-tiled approaches if you want to compare them.
(2) The tileSize attribute changes the size of the blocks the layer should be split into. You can set this to whatever you want. 512x512 really isn't all that large, especially if your PDF dimensions are big. The default is 256x256.
(3) Anytime you start to zoom, oldPDFView is removed and released. Then pdfView is assigned to oldPDFView. When the zooming ends, a new pdfView is created with the change in scale and added on top of the old one. If the new scale is an increase, the new pdfView will be drawn with a higher level of detail. This makes it so you can zoom deeper and deeper into the PDF. The maximumZoomScale and minimumZoomScale only restrict how much you can zoom with an individual gesture.