Last active
September 6, 2022 05:43
-
-
Save 1998code/a7e2fcae66b99c1930c03b1ee29a6b73 to your computer and use it in GitHub Desktop.
Demo of scenePhase (SwiftUI)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ContentView.swift | |
// ScenePhase | |
// | |
// Created by Ming on 6/9/2022. | |
// | |
import SwiftUI | |
struct ContentView: View { | |
@Environment(\.scenePhase) var scenePhase | |
var body: some View { | |
ZStack { | |
VStack(spacing: 15) { | |
Image(systemName: "person.circle.fill") | |
.imageScale(.large) | |
.foregroundColor(.accentColor) | |
Text("Can you see me?") | |
} | |
.padding() | |
if scenePhase == .inactive { | |
inactive | |
} | |
} | |
} | |
var inactive: some View { | |
VStack { | |
Spacer() | |
HStack { | |
Spacer() | |
Text("You cannot see me!") | |
.bold() | |
.font(.largeTitle) | |
.foregroundColor(.accentColor) | |
Spacer() | |
} | |
Spacer() | |
}.background(.ultraThinMaterial) | |
} | |
} | |
struct ContentView_Previews: PreviewProvider { | |
static var previews: some View { | |
ContentView() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment