0

私のコードには、ここで見られるような構造があります。

import SwiftUI

struct ContentView: View {
    var body: some View {
        NavigationView {
            firstView()
        }
    }
}

struct firstView: View {
    var body: some View {
        NavigationLink(
            destination: secondView(),
            label: {
                Text("This is the first view")
            })
            .navigationTitle("First title")
        
    }
}

struct secondView: View {
    var body: some View {
        TabView {
            statsView()
                .tabItem { Text("StatsView") }
            secondStatsView()
                .tabItem { Text("SecondStatsView") }
        }
        .navigationBarTitle(Text("Second Title"))
    }
}

struct statsView: View {
    var body: some View {
        ScrollView {
            VStack {
                Rectangle()
                    .fill(Color.red)
                Rectangle()
                    .fill(Color.green)
                Rectangle()
                    .fill(Color.blue)
                Rectangle()
                    .fill(Color.red)
                Rectangle()
                    .fill(Color.green)
                Rectangle()
                    .fill(Color.blue)
                Rectangle()
                    .fill(Color.red)
                Rectangle()
                    .fill(Color.green)
                Rectangle()
                    .fill(Color.blue)
            }
        }
    }
}

struct secondStatsView: View {
    var body: some View {
        ScrollView {
            VStack {
                Rectangle()
                    .fill(Color.blue)
                Rectangle()
                    .fill(Color.green)
                Rectangle()
                    .fill(Color.red)
                Rectangle()
                    .fill(Color.blue)
                Rectangle()
                    .fill(Color.green)
                Rectangle()
                    .fill(Color.red)
                Rectangle()
                    .fill(Color.blue)
                Rectangle()
                    .fill(Color.green)
                Rectangle()
                    .fill(Color.red)
            }
        }
    }
}

TabView は NavigationView 内にあります。両方の tabItem にスクロールビューがあります。statsView では NavigationBar は自動的に閉じますが、secondStatsView では閉じません (gif を参照)。ユーザーはアプリの最初のページで何かを選択でき、選択後にタブビューが開くため、このコード構成を使用したいと思います。ユーザーはどのタブからでも firstView に戻ることができます。この問題を克服する方法はありますか?

ここに画像の説明を入力

4

0 に答える 0