我想在我的Reality Kit项目中,在一个简单的swiftUI页面和AR摄像机内容视图之间添加一个segue.这是我的SegueView,swiftui页面上有一个按钮,我想将其切换到AR视图.
struct SegueView: View {
@State private var isActive: Bool = false
var body: some View {
NavigationLink(destination: ContentView(rootActive: $isActive), isActive: $isActive, label: {
Text("See in AR")
})
}
}
以下是我的ContentView中的代码,它只呈现一个框:
struct ContentView : View {
@Binding var rootActive: Bool
var body: some View {
return ARViewContainer().edgesIgnoringSafeArea(.all)
}
}
struct ARViewContainer: UIViewRepresentable {
func makeUIView(context: Context) -> ARView {
let arView = ARView(frame: .zero)
// Load the "Box" scene from the "Experience" Reality File
let anchor = AnchorEntity(plane: .horizontal)
let box = ModelEntity(mesh: MeshResource.generateBox(size: 0.3), materials: [SimpleMaterial(color: .blue, isMetallic: true)])
anchor.addChild(box)
// Add the box anchor to the scene
arView.scene.anchors.append(anchor)
return arView
}
func updateUIView(_ uiView: ARView, context: Context) {}
}
我按照this教程创建了segue,但它不包含AR视图,我找不到这样的教程.我还必须在应用程序委托中添加rootActive变量:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Create the SwiftUI view that provides the window contents.
let contentView = ContentView(rootActive: .constant(true))
// Use a UIHostingController as window root view controller.
let window = UIWindow(frame: UIScreen.main.bounds)
window.rootViewController = UIHostingController(rootView: contentView)
self.window = window
window.makeKeyAndVisible()
return true
}
但是由于教程没有这个步骤,我不完全确定该怎么做.当我运行应用程序时,只渲染ContentView.有谁知道我如何创建一个segue,首先呈现SegueView,然后当按下导航链接"在AR中查看"时,它会转到ContentView?
谢谢