导航栏显示模式在SwiftUI中无法完美运行

问题描述 投票:0回答:1

我正在将SwiftUI与版本11.3.1(11C504)一起使用。

我在屏幕上实现标签栏,并且该屏幕将在从登录屏幕导航之后出现。

如果导航displayMode.automatic,那么当我向上滚动列表时,我显示的是空白(在图片中用黑线边框)。否则显示导航标题。当我设置为displayMode时,.inline可以完美工作。当我运行一个项目很多时间,那么一段时间它可以完美地工作,并需要一段时间显示一个空间。

我在图片中提到带有黑色边框的空白。

// ContentView

struct ContentView: View {

    var body: some View {
        HomeTabView()
    }
}

// HomeTabView

struct HomeTabView: View {

    @State private var selection = 0

    //Inclose user intraface of tab View.
    var body: some View {

        TabView(selection: $selection){

            TestListView().tabItem {
                Image(systemName: "book.fill")
                Text("Learn")
            }.tag(0)

            Text("Community").tabItem {
                Image(systemName: "globe")
                Text("Community")
            }.tag(1)

            //Add Notification List on the Screen.
            Text("Notification").tabItem {
                Image(systemName: "bell.fill")
                Text("Notification")

            }.tag(3)

            //Add Account  on the Tab Bar
            Text("Account").tabItem {
                Image(systemName: "person.circle.fill")
                Text("Account")
            }.tag(4)

        }.accentColor(.pink)

            .navigationBarTitle("SwiftUI")
    }

}

TestListView

struct TestListView: View {

    var body: some View {
            VStack{

                List(1...10, id: \.self){ num in
                    ListCards()
                }
              }.edgesIgnoringSafeArea(.all)
       }
}

// ListCards

struct ListCards: View {

    var body: some View {

        ZStack{
        RoundedRectangle(cornerRadius: 16)
                .frame(height: 180)
                .foregroundColor(.white)
                .shadow(radius: 5)

            VStack(alignment: .leading, spacing: 10){

                HStack(alignment: .top){

                    Rectangle()
                        .frame(width: 100, height: 100)
                        .cornerRadius(16)
                        .foregroundColor(.pink)

                    VStack(alignment: .leading, spacing: 4){
                        Text("SwiftUI")
                            .font(.title)

                        Text("Description of title")
                            .foregroundColor(.gray)
                    }
                }
                .padding()

            }.padding(.leading, 2)
        }.padding(.all, 6)
    }
}

enter image description here

scroll uinavigationcontroller swiftui navigationbar displaymode
1个回答
1
投票

您需要以这种方式更改HomeTabView:


var body: some View {

        TabView(selection: $selection) {
            NavigationView {
                TestListView()
                .navigationBarTitle("SWIFTUI")
            }.tabItem {
                Image(systemName: "book.fill")
                Text("Learn")
            }.tag(0)

            NavigationView {
                Text("Community")
            }.tabItem {
                Image(systemName: "globe")
                Text("Community")
            }.tag(1)

            //Add Notification List on the Screen.
            NavigationView {
                Text("Notification")
            }.tabItem {
                Image(systemName: "bell.fill")
                Text("Notification")

            }.tag(3)
            //Add Account  on the Tab Bar
            NavigationView {
                Text("Account")
            }.tabItem {
                Image(systemName: "person.circle.fill")
                Text("Account")
            }.tag(4)

        }.accentColor(.pink)

    }

另外,从TestListView中删除.edgesIgnoringSafeArea(.all)

© www.soinside.com 2019 - 2024. All rights reserved.