首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ios PDFKit displaymode = singlepage仅显示pdf的第一页

ios PDFKit displaymode = singlepage仅显示pdf的第一页
EN

Stack Overflow用户
提问于 2019-03-12 12:16:32
回答 3查看 2.8K关注 0票数 4

我正在尝试通过苹果的PDFKit库在ios上显示一个pdf,而不是使用PDFDisplayMode.singlePageContinuous模式,我想在分页处停下来,所以我尝试使用PDFDisplayMode.singlePage。https://developer.apple.com/documentation/pdfkit/pdfdisplaymode

然而,这种模式似乎只显示pdf的一页,这是相当无用的。我尝试向页面添加卷帘处理程序,但它们也不起作用。

我已经找到了示例应用程序,并修改了它们的代码来测试pdfdisplaymode,但得到了相同的问题,例如https://github.com/vipulshah2010/PDFKitDemo

我如何使用pdfkit实现一次一个页面的pdfviewer,允许在页面之间滑动?!

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2019-04-29 18:59:44

另一种简单的方法是设置

代码语言:javascript
复制
pdfView.usePageViewController(true) 

这为你增加了页面之间的滑动,而不需要设置你自己的手势。如下例所示:

代码语言:javascript
复制
override func viewDidLoad() {
    super.viewDidLoad()

    // Add PDFView to view controller.
    let pdfView = PDFView(frame: self.view.bounds)
    self.view.addSubview(pdfView)

    // Configure PDFView to be one page at a time swiping horizontally
    pdfView.autoScales = true
    pdfView.displayMode = .singlePage
    pdfView.displayDirection = .horizontal
    pdfView.usePageViewController(true)

    // load PDF
    let webUrl: URL! = URL(string: url)
    pdfView.document = PDFDocument(url: webUrl!)
}
票数 11
EN

Stack Overflow用户

发布于 2019-03-12 13:08:32

使用滑动手势识别器(UISwipeGestureRecognizer)让用户向左和向右滑动PDF视图屏幕(PDFView)。

代码语言:javascript
复制
import UIKit
import PDFKit

class ViewController: UIViewController, PDFViewDelegate {
    // MARK: - Variables

    // MARK: - IBOutlet
    @IBOutlet weak var pdfView: PDFView!

    // MARK: - Life cycle
    override func viewDidLoad() {
        super.viewDidLoad()

        let filePath = "/Users/george/Library/Developer/CoreSimulator/Devices/B5C5791C-3916-4BCB-8EB6-5D3D61C08DC0/data/Containers/Data/Application/4B644584-0025-45A7-9D71-C8F8478E4620/Documents/my PDF.pdf"
        pdfView.document = getDocument(path: filePath)
        pdfView.backgroundColor = .lightGray
        pdfView.autoScales = true
        pdfView.displayMode = .singlePageContinuous
        pdfView.usePageViewController(true, withViewOptions: nil)
        createMenu()
        thumbnail()

        /* swipe gesture */
        let leftSwipeGesture = UISwipeGestureRecognizer(target: self, action: #selector(respondLeftSwipeGesture(_:)))
        leftSwipeGesture.direction = [UISwipeGestureRecognizer.Direction.left]
        self.view.addGestureRecognizer(leftSwipeGesture)
        let rightSwipeGesture = UISwipeGestureRecognizer(target: self, action: #selector(respondRightSwipeGesture(_:)))
        rightSwipeGesture.direction = [UISwipeGestureRecognizer.Direction.right]
        pdfView.addGestureRecognizer(rightSwipeGesture)
    }

    @objc func respondLeftSwipeGesture(_ sender: UISwipeGestureRecognizer) {
        if pdfView.document == nil { return }
        pdfView.goToPreviousPage(self)
    }

    @objc func respondRightSwipeGesture(_ sender: UISwipeGestureRecognizer) {
        if pdfView.document == nil { return }
        pdfView.goToNextPage(self)
    }

    func getDocument(path: String) -> PDFDocument? {
        let pdfURL = URL(fileURLWithPath: path)
        let document = PDFDocument(url: pdfURL)
        return document
    }
}
票数 5
EN

Stack Overflow用户

发布于 2019-05-14 07:33:51

您可以简单地将displayMode设置为continuous,它可能会起作用:

代码语言:javascript
复制
pdfView.displayMode = .singlePageContinuous
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55114076

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档