iOS PDFKit禁用垂直滚动弹跳

时间:2019-03-20 15:21:08

标签: ios swift scroll uiscrollview pdfkit

如何使用 PDFKit PDFView中禁用滚动弹跳?

显示PDF的视图没有滚动跳动选项。

这是我的代码:

if let path = Bundle.main.path(forResource: pdfObject, ofType: "pdf") {
    let url = URL(fileURLWithPath: path)
    if let pdfDocument = PDFDocument(url: url) {

        pdfView.autoresizesSubviews = true
        pdfView.autoresizingMask = [.flexibleWidth, .flexibleHeight,
                                    .flexibleTopMargin, .flexibleLeftMargin]

        pdfView.autoScales = true
        pdfView.displaysPageBreaks = true
        pdfView.displayDirection = .vertical
        pdfView.displayMode = .singlePageContinuous
        pdfView.document = pdfDocument

        pdfView.maxScaleFactor = 4.0
        pdfView.minScaleFactor = pdfView.scaleFactorForSizeToFit        
    }
}

预先感谢(这可能是一个非常简单的问题!)

1 个答案:

答案 0 :(得分:1)

很遗憾,没有导出的API来设置PDFView所需的弹跳行为。

话虽如此,您现在可以(安全地)利用PDFView实现细节来破解它:

extension PDFView {

    /// Disables the PDFView default bouncing behavior.
    func disableBouncing() {
        for subview in subviews {
            if let scrollView = subview as? UIScrollView {
                scrollView.bounces = false
                return
            }
        }
        print("PDFView.disableBouncing: FAILED!")
    }
}

,然后在您的代码中像这样使用它:

pdfView.disableBouncing()

注意事项。请记住,这种解决方案可能在将来的iOS版本中可能会中断。不过,请放心,您的应用程序不会因此而崩溃(您完全不会完全禁用反弹行为)。

相关问题