Skip to content

Instantly share code, notes, and snippets.

@1998code
Last active September 6, 2022 05:43
Show Gist options
  • Save 1998code/a7e2fcae66b99c1930c03b1ee29a6b73 to your computer and use it in GitHub Desktop.
Save 1998code/a7e2fcae66b99c1930c03b1ee29a6b73 to your computer and use it in GitHub Desktop.
Demo of scenePhase (SwiftUI)
//
// 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