我正在尝试创建一个带有侧边栏和拆分视图的三列窗口。拆分视图中的每个左视图和右视图都应该有一个相应的 ToolbarItem,显示在它们各自的工具栏/导航标题空间中。
为此,我创建了一个包含侧边栏、左视图和右视图的简单视图。我为左视图创建了一个 ToolbarItem,为右视图创建了另一个 ToolbarItem。但是,属于右视图的 ToolbarItem 显示在左视图的工具栏空间中。有没有办法为每个视图创建特定的 ToolbarItem。任何帮助是极大的赞赏。
下面是我创建的源代码。我还附上了显示该问题的屏幕截图。我正在使用 Xcode 12 测试版和 macOS Big Sur 测试版。
import SwiftUI
struct ContentView: View {
enum NavigationItem {
case demo
}
@State private var selection: Set<NavigationItem> = [.demo]
var body: some View {
NavigationView {
List(selection: $selection) {
Label("Demo", systemImage: "list.bullet")
}
.listStyle(SidebarListStyle())
.frame(minWidth: 200, idealWidth: 250, maxWidth: 300, maxHeight: .infinity)
Text("Left")
.frame(maxWidth: 500, maxHeight: .infinity)
.toolbar {
ToolbarItem {
Button(action: {}) {
Text("Left Toolbar")
}
}
ToolbarItem { Spacer() }
}
.presentedWindowToolbarStyle(ExpandedWindowToolbarStyle())
Text("Right")
.frame(maxWidth: .infinity, maxHeight: .infinity)
.toolbar {
ToolbarItem {
Button(action: {}) {
Text("Right Toolbar")
}
}
}
}
}
}