【问题标题】:iOS PDFView causes underlying assertion when autoScales is set to true当 autoScales 设置为 true 时,iOS PDFView 会导致基础断言
【发布时间】:2021-04-10 12:49:03
【问题描述】:

我正在开发一个需要显示相当大的 PDF 文件的应用程序。我为此使用 PDFKits PDFView,然后将其包装在 UIViewRepresentable 中。问题是在设置PDFView.autoScales = true 时,我在启动时遇到错误。该应用程序仍然有效,autoScales 功能也有效,但我仍然想修复该错误。我还应该提到,在 iOS 开发方面我是一个完全的初学者。

这是我的makeUIView实现:

func makeUIView(context: UIViewRepresentableContext<PDFKitRepresentedView>) -> PDFKitRepresentedView.UIViewType {
    let pdfView = PDFView()
    pdfView.autoScales = true
    pdfView.pageBreakMargins.top = 0.0
    pdfView.pageBreakMargins.bottom = 0.0
    pdfView.pageShadowsEnabled = false
    pdfView.document = PDFDocument(url: self.url)        
    return pdfView
}

这是错误:

[Assert] -[UIScrollView _clampedZoomScale:allowRubberbanding:]: Must be called with non-zero scale
[Unknown process name] CGAffineTransformInvert: singular matrix.

它们似乎会在 PDFView 初始化时被打印出来。任何想法可能是什么问题?

【问题讨论】:

  • 如果它不影响应用程序功能然后忽略它 - 它是 UIKit 内部。
  • 我同意,忽略它可能不是问题。来自系统内部的消息出现在控制台中并不少见。但请尝试在 设置文档和边距之后将 autoScales 设置为 true。
  • @CenkBilgen 不幸的是没有帮助,但是好的,我暂时忽略它,谢谢。

标签: ios swift swiftui uikit ios-pdfkit


【解决方案1】:

我最终只是忽略了它。似乎工作正常。

【讨论】:

    【解决方案2】:

    我也遇到了同样的问题,现在已经解决了。

    你的 pdfView 应该先设置框架。你可以给任何值。

    let pdfView = PDFView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))   
    self.view.addSubview(pdfView)
    

    现在可以了,然后解决错误

    【讨论】:

      猜你喜欢
      • 2020-05-01
      • 1970-01-01
      • 2014-10-26
      • 2023-03-06
      • 1970-01-01
      • 1970-01-01
      • 2017-06-28
      • 2021-02-01
      • 2016-09-05
      相关资源
      最近更新 更多