如何解决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 举报,一经查实,本站将立刻删除。