Created
October 24, 2024 00:59
-
-
Save takoikatakotako/2046a8412a29a25a42001cebe57b52e8 to your computer and use it in GitHub Desktop.
SwiftUIでアプリ起動時に画面を遷移させる
This file contains hidden or 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
| 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