iOS PDFKit禁用垂直滚动弹跳

问题描述 投票:2回答:1

如何使用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        
    }
}

在此先感谢(因为这可能是一个非常简单的问题!)

ios swift scroll uiscrollview pdfkit
1个回答
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版本中中断。不过,请放心,您的应用程序不会因此而崩溃(您根本不会禁用弹跳行为)。

© www.soinside.com 2019 - 2024. All rights reserved.