PDF View with horizontal scroll(水平滚动的 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 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.
请记住,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 视图
- URL编码Swift iOS 2022-01-01
- 网上有没有好的 UIScrollView 教程? 2022-01-01
- 在 Iphone SDK 的导航栏上添加多个按钮 2022-01-01
- Xcode 7.3 中带有 UILabel 的 UIStackView 2022-01-01
- 使用自动布局向 UIScrollView 添加动态大小的视图 2022-01-01
- UITextView 内容插图 2022-01-01
- 如何在 iPhone 模拟器中重置 NSUserDefaults 数据? 2022-01-01
- 类似于 Mail.app 的 iPad 模态视图控制器? 2022-01-01
- GPS状态的广播接收器? 2022-01-01
- SetOnItemSelectedListener上的微调程序错误 2022-01-01