我正在尝试在 SwiftUI中使用AR Quick Look 。我没有找到任何教程——只有关于 AR Quick Look 和 UIKit 的教程。我是 Swift 开发的新手,所以我不知道如何将 UIKit 视图放置在 SwiftUI 视图中。
这是我想在 SwiftUI 中显示的带有 UIKit 的代码:
import UIKit
import QuickLook
import ARKit
class ViewController: 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: "myScene", ofType: "reality") else { fatalError("Couldn't find the supported input file.") }
let url = URL(fileURLWithPath: path)
return url as QLPreviewItem
}
}