【问题标题】:PDFKit - PdfView won't be RTL without usePageViewController()PDFKit - 没有 usePageViewController() PdfView 不会是 RTL
【发布时间】:2021-01-31 14:25:23
【问题描述】:

我想水平显示PDF,页面从右到左,逐页连续显示,用户捏一页会使所有页面同步相同的比例。

我写的代码如下:

        if let pdfDocument = PDFDocument(url: pdfUrl) {
            pdfView.document = pdfDocument
            pdfView.displayMode = .singlePageContinuous
            pdfView.displaysRTL = true
            pdfView.autoScales = true
            pdfView.autoresizesSubviews = true
            pdfView.displayDirection = .horizontal
            pdfView.displaysPageBreaks = true
            pdfView.pageBreakMargins = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
            
            pdfView.maxScaleFactor = 4.0
            pdfView.minScaleFactor = pdfView.scaleFactorForSizeToFit
        }

但显示RTL 不起作用,默认比例不会显示整个单页,而是适合PDF页面高度(页面右侧将超出屏幕)。

如果我添加

pdfView.usePageViewController(true)

PDF displayRTL 有效,默认情况下每个页面都适合屏幕大小。但是这样会导致PDF不能一页一页显示,放大比例也不会和其他页面一样。

左侧页面比例与右侧当前放大页面不同。如果用户捏页面,我需要它们都具有相同的比例。

有没有办法解决这个问题?

另外,每个页面的左上角都会显示一个图标,不知道是什么意思,怎么隐藏..

【问题讨论】:

    标签: ios swift pdfkit pdfview


    【解决方案1】:

    我找到了一种让它手动显示RTL的方法。
    不要使用usePageViewController(true),而只是对 PDFDocument 中的页面重新排序。

    let doc = PDFDocument()
    var getPage = pdfDocument.pageCount - 1
    for i in 0..<pdfDocument.pageCount {
        guard let pageRef = pdfDocument.page(at: getPage) else { fatalError() }
        doc.insert(pageRef, at: i)
        getPage -= 1
    }
    pdfView.document = doc
    
    // Display PDF from last page if Right to Left
    if (isPageRTL) {
        pdfView.goToLastPage()
    } 
    

    我发现如果 PDF 在 iOS 12 和 iOS 13 中很大(iOS 14 似乎没问题),Apple 的 PDFView 会出现内存泄漏和崩溃。所以我必须找到其他方式来显示适合我需要的 PDF。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-11-11
      • 2019-07-06
      • 2019-12-21
      • 2020-09-04
      • 2018-12-06
      • 2019-01-07
      • 1970-01-01
      • 2022-01-01
      相关资源
      最近更新 更多