【发布时间】:2020-12-16 01:26:12
【问题描述】:
我有一个 .fullScreenCover,当我到达我的应用程序中的某个点时会打开。当我想关闭它并重置应用程序时,我关闭视图并将 ContentView ID 设置为新的 UUID()。这是我的主要应用代码:
class AppState: ObservableObject {
static let shared = AppState()
@Published var gameID = UUID()
}
@main
struct RugbyAppApp: App {
@StateObject var appState = AppState.shared
var body: some Scene {
WindowGroup {
ContentView().id(appState.gameID)
}
}
}
这应该会在我每次打开 ContentView 时生成一个新 ID。当我在按钮中使用另一个 UUID() 更改游戏 ID 以重新启动时,presentationMode.wrappedValue.dismiss() 停止工作,这意味着我无法再返回该视图。
Button("New Game"){
AppState.shared.gameID = UUID() //Line x
presentationMode.wrappedValue.dismiss()
}
根据 Cod3rMax 的评论,这就是我所说的 fullScreenCover:
Button(action: {endGameAlert.toggle()}) {
TopPanelButton(buttonText: "End Game", buttonColour: Color.red, buttonWidth: geometry.size.width/10, buttonHeight: geometry.size.width/30)
}
.alert(isPresented: $endGameAlert){
Alert(title: Text("Are You Sure?"), message: Text("Do you want to end the game?"),
primaryButton: Alert.Button.default(Text("End Game"), action: {
stopWatchManager.endGame()
processor.textReport(homeTeam: homeTeam, awayTeam: awayTeam)
exportToPDF(homeTeam: homeTeam, awayTeam: awayTeam, events: processor.matchEvents)
showEnd.toggle()
}),
secondaryButton: Alert.Button.cancel(Text("Cancel"), action: {})
)
}
}
.fullScreenCover(isPresented: $showEnd){
EndGameScreen(homeTeam: homeTeam, awayTeam: awayTeam)
}
【问题讨论】:
-
你能把完整的代码贴出来
-
我现在添加了更多代码!