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 视图
基础教程推荐
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01