简体   繁体   English

SwiftUI MacOS QuickLook 文件预览

[英]SwiftUI MacOS QuickLook preview of files

I am trying to display a preview of files (like PDF, Pages, Microsoft Docs) in my SwiftUI application for MacOS.我正在尝试在适用于 MacOS 的 SwiftUI 应用程序中显示文件预览(如 PDF、Pages、Microsoft Docs)。

I found Apple's QuickLook framework, which looks perfect for that use.我找到了 Apple 的QuickLook框架,它看起来非常适合这种用途。 Can I use it in SwiftUI?我可以在 SwiftUI 中使用它吗? If I look up the documentation at Apple, I find the QLPreviewController which is a UIViewController.如果我查看 Apple 的文档,我会找到QLPreviewController ,它是一个 UIViewController。

My approach would, to wrap that UIViewController into a SwiftUI view.. is that the best way?我的方法是,将 UIViewController 包装到 SwiftUI 视图中..这是最好的方法吗? Has anyone tried to do that already?有没有人尝试过这样做?

Summary: how can I display file previews in my SwiftUI MacOS app?摘要:如何在我的 SwiftUI MacOS 应用程序中显示文件预览?

So, I figured it out finally.所以,我终于想通了。

I was able to use the QLPreviewView , which generates a preview view for me.我能够使用QLPreviewView ,它为我生成预览视图。 I wrapped it inside a NSViewRepresentable and it worked :)我把它包裹在一个NSViewRepresentable ,它起作用了:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM