Hello! I'm a very new developer and I was looking for an example of how you use an AR Quick Look preview in SwiftUI, I really appreciate the help!
How do you use AR Quick Look in SwiftUI?
In swiftui + realitykit, I successfully call up quick look through windowgroup, but I can't close it.
WindowGroup:
import SwiftUI
struct ARQuickLookApp: App {
var body: some Scene {
WindowGroup {
Content1View()
}
}
}
AR Quick Look:
import SwiftUI
import QuickLook
import RealityKit
import ARKit
struct Content1View: View {
var body: some View {
ARQLView1Controller()
}
}
struct ARQLView1Controller: UIViewControllerRepresentable {
func makeUIViewController(context: Context) -> some UIViewController {
return UINavigationController.init(rootViewController: View1Controller())
}
func updateUIViewController(_ uiViewController: UIViewControllerType, context: Context) {
}
}
class View1Controller: UIViewController, QLPreviewControllerDataSource {
override func viewDidAppear(_ animated: Bool) {
let previewController = QLPreviewController()
previewController.dataSource = self
present(previewController, animated: true, completion: nil)
}
func numberOfPreviewItems(in controller: QLPreviewController) -> Int { return 1 }
func previewController(_ controller: QLPreviewController, previewItemAt index: Int) -> QLPreviewItem {
guard let path = Bundle.main.path(forResource: "U1CrystalCell", ofType: "reality") else { fatalError("Couldn't find the supported input file.") }
let url = URL(fileURLWithPath: path)
return url as QLPreviewItem
}
}