Nic*_*mer 5 scroll pdfkit uiscrollview ios swift
如何在PDFView使用PDFKit 时禁用滚动反弹?
显示 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
}
}
Run Code Online (Sandbox Code Playgroud)
提前致谢(可能是一个非常简单的问题!)
不幸的是,没有导出的 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!")
}
}
Run Code Online (Sandbox Code Playgroud)
然后在您的代码中像这样使用它:
pdfView.disableBouncing()
Run Code Online (Sandbox Code Playgroud)
警告。请记住,此类解决方案可能会在未来的 iOS 版本中崩溃。不过,请放心,您的应用程序不会因此崩溃(您只是根本不会禁用弹跳行为)。
| 归档时间: |
|
| 查看次数: |
988 次 |
| 最近记录: |