水平滚动的 PDF 视图

PDF View with horizontal scroll(水平滚动的 PDF 视图)

本文介绍了水平滚动的 PDF 视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得一些关于如何实现水平滚动的 PDF 视图的提示.

I'd like to get some tip about how implement a PDF View that scrolls horizontally.

我知道如何使用 UIWebView 实现 PDF 阅读器,但只是垂直滚动.

I know how implement a PDF reader using UIWebView, but just with vertically scroll.

推荐答案

我已经做到了.代码对于付费客户是私有的,所以我不能直接分享,但基本思路是这样写:

I've done this. The code was private for a paying customer, so I can't share it directly, but the basic idea is to write:

  • 一个 UIView 子类,它使用 CGPDFPageRef 以及 CGPDFDocument*CGContextDrawPDFPage 系列职能.此视图从 layerClass 类方法返回 [CATiledLayer class] 并适当地设置图层的 levelsOfDetail 和 tileSize 属性有很大帮助.我的也实现了 sizeThatFits 来返回页面大小加上一个小间距,并在 pdf 页面的边缘呈现一个微妙的阴影.

  • One UIView subclass that renders a single page of a PDF, using a CGPDFPageRef and the CGPDFDocument* and CGContextDrawPDFPage families of functions. It helps a great deal for this view to return [CATiledLayer class] from the layerClass class method, and to set the layer's levelsOfDetail and tileSize properties appropriately. Mine also implements sizeThatFits to return the page size plus a small gutter, and renders a subtle dropshadow around the edge of the pdf page.

请记住,UIKit 绘图与 CG 绘图是颠倒的;CGContextTranslateCTM(ctx, 0.0, layer.bounds.size.height);CGContextScaleCTM(ctx, 1.0, -1.0); 绘制前.

Remember that UIKit drawing is upside-down from CG drawing; so do a CGContextTranslateCTM(ctx, 0.0, layer.bounds.size.height); CGContextScaleCTM(ctx, 1.0, -1.0); before painting.

一个 UIView 子类包含和布局(并被委托)处于分页模式的 UIScrollView(主水平寻呼机),以及每个页面的单独 UIScrollView,每个页面都包含上述视图之一(用于放大单独的页面.)嵌套滚动视图是Apple明确认可的做这种事情的方式.这个视图需要按照你想要的方式布置页面;大概在一个长的水平条中,每个都缩放到合适的大小.

One UIView subclass containing and laying out (and being delegate for) a UIScrollView in paging mode (the main horizontal pager), and an individual UIScrollView for each page, each containing one of the above views (for zooming into individual pages.) Nested scroll views is Apple's explicitly endorsed way of doing this sort of thing. This view will need to lay out the pages how you want them; presumably in one long horizontal strip, each zoomed to a fitting size.

如果不需要页面缩放,可以跳过嵌套的滚动视图,直接在水平滚动条中布局页面视图.

If you don't need page zooming, you can skip the nested scroll views and lay out the page views directly in the horizontal scroller.

TL;DR: 不幸的是,这并不像把它扔进 UIWebView 那样简单;但这是可行的,而且直接的方法确实有效.

TL;DR: Unfortunately it's not as simple as tossing it in a UIWebView; but it is doable, and the straightforward approach does work.

这篇关于水平滚动的 PDF 视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:水平滚动的 PDF 视图