SwiftUI:QuickLook在iPad设备中无法正常运行

问题描述

我尝试使用QuickLook框架。

为了编辑PDF,我在Coordinator中实现了“ previewController(_:editingModeFor :)”。

在Xcode(ver 11.6)模拟器中,quicklook视图具有铅笔标记工具。 In Xcode simulator

但是在我的iPad(PadOS 13.6)中,没有标记工具。 In my iPad device,PadOS 13.6

QuickLook框架中是否存在任何错误

这是我的代码

PreviewController.swift

import SwiftUI
import QuickLook
struct PreviewController: UIViewControllerRepresentable {
    let url: URL
    @Binding var isPresented: Bool
    func makeUIViewController(context: Context) -> UINavigationController {
        let controller = QLPreviewController()
        controller.dataSource = context.coordinator
        controller.delegate = context.coordinator
        let navigationController = UINavigationController(rootViewController: controller)
        return navigationController
    }
    func updateUIViewController(_ uiViewController: UINavigationController,context: Context) {}
    func makeCoordinator() -> Coordinator {
        return Coordinator(parent: self)
    }
    class Coordinator: NSObject,QLPreviewControllerDelegate,QLPreviewControllerDataSource {
        let parent: PreviewController
        init(parent: PreviewController) {
            self.parent = parent
        }
        func numberOfPreviewItems(in controller: QLPreviewController) -> Int {
            return 1
    }
    func previewController(_ controller: QLPreviewController,previewItemAt index: Int) -> QLPreviewItem {
    return parent.url as NSURL
    }
    /* 
Return .updateContents so QLPreviewController takes care of updating the contents of the provided QLPreviewItems whenever users save changes.
*/    
    func previewController(_ controller: QLPreviewController,editingModeFor previewItem: QLPreviewItem) -> QLPreviewItemEditingMode {
    return .updateContents
        }
    }
}

ContentView.swift

import SwiftUI
struct ContentView: View {
    let fileUrl = Bundle.main.url(forResource: "LoremIpsum",withExtension: "pdf")!
    @State private var showingPreview = false
    var body: some View {
        Button("Preview File") {
            self.showingPreview = true
        }
        .sheet(isPresented: $showingPreview) {
            PreviewController(url: self.fileUrl,isPresented: self.$showingPreview)
        }
    }
}

解决方法

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

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

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

相关问答

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