【发布时间】:2022-01-20 20:09:10
【问题描述】:
我正在尝试找出从 SpriteKit 场景移回 SwiftUI 视图的正确方法。我目前有一个 Swift UI “主菜单”,看起来像这样。
struct MainMenu: View {
var body: some View {
NavigationView {
VStack {
Text("Replicator")
.font(.largeTitle)
.fontWeight(.bold)
.padding()
NavigationLink(destination: ContentView().navigationBarBackButtonHidden(true)) {
HStack {
Image(systemName: "play.circle")
.font(.title3)
Text("Start")
.font(.title)
}
.frame(width: 250, height: 50)
.background(.cyan)
.cornerRadius(25)
.foregroundColor(.white)
}
}
}
}
}
ContentView() 是包含 SpriteKit 游戏的内容,如下所示。
struct ContentView: View {
var scene: SKScene {
let scene = Level_1()
scene.size = CGSize(width: 750, height: 1334)
scene.scaleMode = .aspectFit
return scene
}
var body: some View {
VStack {
SpriteView(scene: scene)
.ignoresSafeArea()
}
}
}
我的问题是……进入 ContentView 后如何返回“主菜单”?
感谢您提供的任何帮助。
【问题讨论】:
标签: swift swiftui sprite-kit