Skip to content

Instantly share code, notes, and snippets.

@takoikatakotako
Created October 24, 2024 00:59
Show Gist options
  • Select an option

  • Save takoikatakotako/2046a8412a29a25a42001cebe57b52e8 to your computer and use it in GitHub Desktop.

Select an option

Save takoikatakotako/2046a8412a29a25a42001cebe57b52e8 to your computer and use it in GitHub Desktop.
SwiftUIでアプリ起動時に画面を遷移させる
import SwiftUI
struct ContentView: View {
@State var viewType: ViewType = .launch
var body: some View {
ZStack {
switch viewType {
case .launch:
Text("Launch")
case .home:
Text("Home")
}
}
.onAppear {
Task {
try? await sleep()
withAnimation(.linear(duration: 0.5)) {
viewType = .home
}
}
}
}
func sleep() async throws {
// sleep 2sec
_ = try await Task.sleep(nanoseconds: 2_000_000_000)
}
}
#Preview {
ContentView()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment