LoginSignup
1
2

More than 1 year has passed since last update.

SwiftUIでスプラッシュ画面を実装してみた

Posted at

はじめに

今回、アプリの初期起動時のみに表示される画面を実装したので、メモします。

実装方法

やったこととしては、とてもシンプルで画面起動時にContentView内で分岐処理をして切り替えただけです。

code
import SwiftUI

struct ContentView: View {

    @State private var isLoading = true
    @State var selectedTag = 1

    var body: some View {
        if isLoading{
            // 画面起動時に呼ばれる
            // StartUpViewは、別で作ったViewになります
            StartUpView().onAppear {
                // 画面が起動してから1.5秒後に[isLoading = false]を代入
                DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) {
                    withAnimation {
                        isLoading = false
                    }
                }
            }
        }else{
            TabView(selection: $selectedTag){
                HomeView().tabItem {
                    Image(systemName: "house")
                    Text("ホーム")
                }.tag(1)
                ShopMapView().tabItem {
                    Image(systemName: "map")
                    Text("アクセス")
                }.tag(2)
            }
        }
    }
}

実装画面

beautyMovie.gif

おわりに

上手くできてよかったです:blush:

参考記事
https://qiita.com/uhooi/items/ce31c80b7f5035e20be7

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2