我有这 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)
}
}
}