You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: QuickStart/iOS/Game States/5 - TitleState/5C - TitleUI.swift
+28-19Lines changed: 28 additions & 19 deletions
Original file line number
Diff line number
Diff line change
@@ -28,22 +28,25 @@ struct TitleUI: View {
28
28
staticvarsuppressAppearanceAnimation=false
29
29
30
30
/// This flag controls the display of superficial UI for demonstration.
31
-
@StateprivatevarshowMoreUI=showMoreUIGlobal{
31
+
@StateprivatevarshowHUD=TitleUI.showHUDGlobal{
32
32
didSet {
33
-
TitleUI.showMoreUIGlobal=showMoreUI
33
+
TitleUI.showHUDGlobal=showHUD
34
34
}
35
35
}
36
36
37
-
/// Since TitleUI is also used in PlayUI, we copy the showMoreUI setting to a static variable which persists across multiple game states, otherwise it would get reset when the game state changes.
38
-
staticvarshowMoreUIGlobal=false
37
+
/// Since TitleUI is also used in PlayUI, we copy the showHUD setting to a static variable which persists across multiple game states, otherwise it would get reset when the game state changes.
38
+
staticvarshowHUDGlobal=false
39
39
40
+
/// This flag is set to `false` after the HUD is shown, to prevent it from reanimating when TitleUI is shown inside PlayUI after the game state changes.
41
+
@StateprivatevaranimateHUDAppearance=true
42
+
40
43
varbody:someView{
41
44
42
45
VStack{
43
46
44
47
Spacer()
45
48
46
-
moreUI
49
+
hudUI
47
50
48
51
Spacer()
49
52
@@ -62,8 +65,8 @@ struct TitleUI: View {
62
65
}
63
66
}
64
67
.onAppear{
65
-
// Set a flag to start the initial animation.
66
-
self.didAppear=true
68
+
self.didAppear =true// Set a flag to start the initial animation.
69
+
self.showHUD=TitleUI.showHUDGlobal // Sync the instance and global flags.
67
70
}
68
71
69
72
}
@@ -77,7 +80,7 @@ struct TitleUI: View {
77
80
78
81
VStack{
79
82
80
-
toggleMoreUIButton
83
+
toggleHUDButton
81
84
82
85
nextStateButton
83
86
@@ -99,8 +102,8 @@ struct TitleUI: View {
99
102
}
100
103
}
101
104
102
-
vartoggleMoreUIButton:someView{
103
-
Button(action:toggleMoreUI){
105
+
vartoggleHUDButton:someView{
106
+
Button(action:toggleHUD){
104
107
QuickStartButtonLabel(text:"TOGGLE MORE UI", color:.purple)
0 commit comments