PDF View with horizontal scroll
I'd like to get some tip about how implement a PDF View that scrolls horizonta开发者_开发百科lly.
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:
One UIView subclass that renders a single page of a PDF, using a
CGPDFPageRef
and theCGPDFDocument*
andCGContextDrawPDFPage
families of functions. It helps a great deal for this view to return[CATiledLayer class]
from thelayerClass
class method, and to set the layer's levelsOfDetail and tileSize properties appropriately. Mine also implementssizeThatFits
to return the page size plus a small gutter, and renders a subtle dropshadow around the edge of the pdf page.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.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: Unfortunately it's not as simple as tossing it in a UIWebView; but it is doable, and the straightforward approach does work.
I found an open project with this feature =D
https://github.com/iamruinous/Reader
I found an open project with this feature
https://github.com/vfr/Reader
精彩评论