Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
435 views
Welcome To Ask or Share your Answers For Others

1 Answer

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 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.

    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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...