我有一個三列布局的 macOS 應用程式,第一個是側邊欄。我有一個按鈕可以切換,使用戶能夠隱藏側邊欄。
在 Xcode 和其他 macOS 上,切換側邊欄按鈕位于側邊欄頂部的工具列上,并在側邊欄隱藏時成為主工具列的一部分。
例如,在 Xcode 上打開側邊欄:

當您隱藏側邊欄時:

我已將帶有切換側邊欄的工具列添加到包含我的側邊欄的視圖中,并將另一個工具列添加到第二列,但切換側邊欄仍然出現在第二列頂部的主工具列上。
我錯過了什么嗎?這是代碼:
// sidebar view, first of three columns
struct ContentView: View {
@State var selection: Set<Int> = [0]
var body: some View {
NavigationView {
List(selection: self.$selection) {
NavigationLink(destination: AllData()) {
Label("All Data", systemImage: "note.text")
}
.tag(0)
Label("Trash", systemImage: "trash")
}
.listStyle(SidebarListStyle())
.toolbar {
ToolbarItem(placement: .navigation) {
Button(action: toggleSidebar, label: {
Image(systemName: "sidebar.left") }).help("Toggle Sidebar")
}
}
}
}
func toggleSidebar() {
NSApp.keyWindow?.firstResponder?.tryToPerform(#selector(NSSplitViewController.toggleSidebar(_:)), with: nil)
}
}
// second column view, with the rest of the toolbar
struct AllData: View {
var body: some View {
NavigationView {
List(filteredData) {
// list items here.
}
.toolbar {
ToolbarItem(placement: .automatic) {
Button("Press Me") {
print("Pressed")
}
}
ToolbarItem(placement: .automatic) {
Button("Press Me too") {
print("Pressed too")
}
}
}
}
}
}
uj5u.com熱心網友回復:
嘗試這個:
ToolbarItem(placement: .primaryAction) {

轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/430622.html
上一篇:Python使用帶有私鑰的子行程
下一篇:虛擬分類變數的條形圖
