当帧动画时,Swift PDFView跳转

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

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

[我尝试使用UIView.animate和UIViewPropertyAnimator设置动画,并将PDFView添加为子视图并为父级添加动画,但是所有这些都会导致相同的问题。

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

enter image description here

谢谢!

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个回答
0
投票

我几个月来一直在寻找添加此功能的方法,但一直无法解决。但是,当我问这个问题时,似乎我就回答了。

您需要设置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进行动画处理时对其进行滚动,则它的行为仍然很有趣,但还不错。

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