Home IOS Development ios – Why does not QLPreviewController work in SwiftUI TabView?

ios – Why does not QLPreviewController work in SwiftUI TabView?

0
ios – Why does not QLPreviewController work in SwiftUI TabView?

[ad_1]

I can’t discover a approach to get QuickLook(QLPreviewController) to load a pdf inside a SwiftUI TabView. Is there a approach to make this work? It’s particularly once I inform Tabview to be a .web page View.

struct QuickLookView: View {
    @State personal var url: URL = Bundle.principal.url(forResource: "Pattern-PDF", withExtension: "pdf")!
    @State personal var tab: Int = 0
    var physique: some View {
        NavigationStack {
            TabView(choice: $tab) {
                ForEach(0..<3) { num in
                    PreviewController(url: url).tag(num)
                }
            }
            .tabViewStyle(.web page(indexDisplayMode: .by no means))
        }
    }
}
struct PreviewController: UIViewControllerRepresentable {
    let url: URL
    
    func makeUIViewController(context: Context) -> QLPreviewController {
        let controller = QLPreviewController()
        controller.dataSource = context.coordinator
        return controller
    }
    
    func updateUIViewController(
        _ uiViewController: QLPreviewController, context: Context) {}
    
    
    func makeCoordinator() -> Coordinator {
        return Coordinator(guardian: self)
    }
    
    class Coordinator: NSObject, QLPreviewControllerDataSource, UIGestureRecognizerDelegate {
        
        let guardian: PreviewController
        
        init(guardian: PreviewController) {
            self.guardian = guardian
        }
        
        func numberOfPreviewItems(in controller: QLPreviewController) -> Int {
            return 1
        }
        
        func previewController(_ controller: QLPreviewController, previewItemAt index: Int) -> QLPreviewItem {
            return guardian.url as NSURL
        }
    }
}

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here