我有一个如下所示的 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)
}
}
问题: 当我点击“New Listing”选项卡时,如何使NewListingView
以模态形式(在SwiftUI中称为sheet)显示?
SheetPresenter
的主体中使用Rectangle
组件代替那个空的Text
。 - nayemColor.clear
来实现这个目的。 - ramzesenok