PDF用水平滚动查看 [英] PDF View with horizontal scroll

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

问题描述



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

解决方案

我做到了。代码对于付费客户是私有的,所以我不能直接共享,但基本想法是写:




  • 一个UIView子类,它使用 CGPDFPageRef CGPDFDocument * CGContextDrawPDFPage 系列函数。它有助于此视图从 layerClass 类方法中返回 [CATiledLayer类] ,并设置层的levelsOfDetail和tileSize属性。 Mine还实现 sizeThatFits 以返回页面大小加上一个小槽,并在pdf页面的边缘呈现微妙的阴影。



    记住,UIKit绘图是从CG绘图倒置的;所以做一个 CGContextTranslateCTM(ctx,0.0,layer.bounds.size.height);


  • 一个UIView子类包含和布局(并且被委托)一个UIScrollView在分页模式(主水平分页器)和一个单独的UIScrollView每个页面,每个包含上述视图之一(用于放大单个页面。)嵌套滚动视图是苹果公司明确认可的做这种事情的方式。这个视图将需要按照你想要的方式布局页面;



    如果你不需要页面缩放,你可以跳过嵌套的滚动视图和布局页面




TL; DR:不幸的是,它并不像在UIWebView中那样简单;但它是可行的,直接的方法工作。


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.

解决方案

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.

这篇关于PDF用水平滚动查看的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆