SwiftUI当前视图通过TabView模态化吗?

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

我的TabView设置如下:

struct ContentView: View {
    @State private var selection = 0
    @State var newListingPresented = false

    var body: some View {
        TabView(selection: $selection){

            // Browse
            BrowseView()
                .tabItem {
                    VStack {
                        Image(systemName: (selection == 0 ? "square.grid.2x2.fill" : "square.grid.2x2"))
                    }
                }
                .tag(0)


            // New Listing
            NewListingView()
                .tabItem {
                    VStack {
                        Image(systemName: (selection == 1 ? "plus.square.fill" : "plus.square"))
                    }
                }
                .tag(1)

            // Bag
            BagView()
                .tabItem {
                    VStack {
                        Image(systemName: (selection == 2 ? "bag.fill" : "bag"))
                    }
                }
                .tag(2)

            // Profile
            ProfileView()
                .tabItem {
                    VStack {
                        Image(systemName: (selection == 3 ? "person.crop.square.fill" : "person.crop.square"))
                    }
                }
                .tag(3)
        }.edgesIgnoringSafeArea(.top)
    }
}

问题:点击时,如何获取“新列表”选项卡以模态显示NewListingView(在SwiftUI中称为工作表?)?

我的T​​abView设置如下:struct ContentView:View {@State私有var选择= 0 @State var newListingPresented = false var正文:某些视图{TabView(selection:$ ...

ios swift xcode swiftui tabview
1个回答
0
投票
我认为您正在寻找this解决方案。制作空的tabItem(Text(" ")),在所需位置设置Image,然后使用.onTapGesture。在该答案中,我仅显示如何显示ActionSheet
© www.soinside.com 2019 - 2024. All rights reserved.