【问题标题】:Swift PDFView jumps when frame is animated框架动画时Swift PDFView跳转
【发布时间】:2020-07-06 14:09:39
【问题描述】:

我有一个具有全屏 PDFView 的应用程序,我正在尝试在屏幕顶部添加一个动画标签栏。但是,每当我为 PDFView 的框架设置动画以显示选项卡栏时,视图中加载的 PDF 都会跳转到另一个位置。

我尝试使用 UIView.animate 和 UIViewPropertyAnimator 进行动画处理,并将 PDFView 添加为子视图并对父视图进行动画处理,但都会导致相同的问题。

有人遇到过这个问题吗?关于如何以一种可以带来流畅用户体验的方式创建动画的任何想法?标签栏显然可以在 PDFView 之上进行动画处理,但我不喜欢它覆盖 PDF 的想法。

谢谢!

func CreatePDFView() {
    pdfView.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height)
    view.addSubview(pdfView)
}
func AnimatePDFView() {
    UIView.animate(withDuration: 1) {
        self.pdfView.frame = CGRect(x: 0, y: 40, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height - 40)
    }
}

【问题讨论】:

    标签: ios swift pdfkit uianimation pdfview


    【解决方案1】:

    几个月来我一直在寻找添加此功能,但未能解决此问题。不过,我一问这个问题,似乎就问了。

    您需要为 pdfView.documentView?.frame 设置动画,并补偿当前帧。我用 UIEdgeInsets 做了这个,它似乎工作。

    if tabDocumentBrowserIsVisible {
            tabDocumentBrowser.Animate(toState: .hidden)
            UIView.animate(withDuration: 0.3) {
                let inset = UIEdgeInsets(top: -80, left: 0, bottom: 0, right: 0)
                self.pdfView.documentView?.frame = self.pdfView.documentView?.frame.inset(by: inset) as! CGRect
            }
            tabDocumentBrowserIsVisible = false
        } else {
            tabDocumentBrowser.Animate(toState: .visible)
            UIView.animate(withDuration: 0.3) {
                let inset = UIEdgeInsets(top: 80, left: 0, bottom: 0, right: 0)
                self.pdfView.documentView?.frame = self.pdfView.documentView?.frame.inset(by: inset) as! CGRect
            }
            tabDocumentBrowserIsVisible = true
        }
    

    如果您在制作动画时滚动 PDF,它的行为仍然有点滑稽,但也不算太糟糕。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-31
      • 2016-09-28
      • 2020-09-04
      • 2022-06-15
      • 1970-01-01
      • 2011-10-08
      相关资源
      最近更新 更多