UIDocumentInteractionController的演示动画似乎不正确

问题描述

我建立了一个用于预览文档的辅助类,如下:

import Foundation
import UIKit
import CoreServices

class Previewer: NSObject {
    
    private static var instance = Previewer()

    private var documentController: UIDocumentInteractionController?

    private var currentViewController: UIViewController?
    
    private var currentView: UIView?
    
    private var isPresenting: Bool = false

    private override init() {}

    static func open(localUrl: URL,filename: String? = nil,for viewController: UIViewController,for view: UIView? = nil) {
        if instance.isPresenting { return }
        
        instance.currentViewController = viewController
        instance.currentView = view
        instance.documentController = UIDocumentInteractionController(url: localUrl)
        instance.documentController?.delegate = Previewer.instance
        instance.documentController?.name = filename
        if let uti = findUti(from: filename) {
            instance.documentController?.uti = uti
        }
        instance.isPresenting = instance.documentController?.presentPreview(animated: true) ?? false
    }
    
    private static func findUti(from filename: String?) -> String? {
        if let filename = filename,let fileExtension = URL(string: filename)?.pathExtension,let uti = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension,fileExtension as CFString,nil) {
           return String(uti.takeRetainedValue())
        }
        return nil
    }
    
}

extension Previewer: UIDocumentInteractionControllerDelegate {

    func documentInteractionControllerViewControllerForPreview(_ controller: UIDocumentInteractionController) -> UIViewController {
        return self.currentViewController!
    }
    
    func documentInteractionControllerViewForPreview(_ controller: UIDocumentInteractionController) -> UIView? {
        return self.currentViewController?.view
    }
    
    func documentInteractionControllerRectForPreview(_ controller: UIDocumentInteractionController) -> CGRect {
        return self.currentViewController?.view.frame ?? .zero
    }
    
    func documentInteractionControllerDidEndPreview(_ controller: UIDocumentInteractionController) {
        self.documentController = nil
        self.isPresenting = false
        self.currentViewController = nil
        self.currentView = nil
    }
    
}

我在给定的控制器中以这种方式使用它:

Previewer.open(localUrl: "file:///...../photo.jpg",filename: "photo.jpg",for: self,for: self.imageView)

效果很好。关键是演示动画仍然是认动画(从底部开始显示+淡入淡出)。

从文档中:

// If preview is supported,these provide the view and rect that will be used as the starting point for the animation to the full screen preview.
// The actual animation that is performed depends upon the platform and other factors.
// If documentInteractionControllerRectForPreview is not implemented,the specified view's bounds will be used.
// If documentInteractionControllerViewForPreview is not implemented,the preview controller will simply fade in instead of scaling up.

有人从委托中提供的视图的rect开始设法获得适当的动画吗?我无法按照文档中的说明进行操作。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...