我有这 2 个视图,当点击 EditButton
时,我想交换其中的两个(TestView/BottomToolbar
和 BottomView/TabView
)。
TestView/BottomToolbar
可见。BottomView/TabView
隐形。我可以做这样的事情吗?如果是,如何?
struct BottomView: View {
@State private var tabSelection = 0
var body: some View {
TabView(selection: $tabSelection) {
TestView().tabItem {
Image(systemName: "tray")
}.tag(0)
AnotherView().tabItem {
Image(systemName: "house")
}.tag(1)
}
}
}
struct TestView: View {
@State private var list = [1,2,3,4,5]
@State private var selection = Set<Int>()
@State var editMode: EditMode = .inactive
var body: some View {
NavigationView {
List(selection: $selection) {
ForEach(list, id: \.self) { item in
Text("\(item)")
}
}
.toolbar {
ToolbarItemGroup(placement: .navigationBarLeading) {
EditButton()
}
ToolbarItemGroup(placement: .bottomBar) {
if editMode == .active {
Button("Approve") { }
Spacer()
Button("Reject") { }
}
}
}
.environment(\.editMode, $editMode)
}
}
}