MagicCarpetPilot
MagicCarpetPilot

Reputation: 56

SwiftUI Mac OS toolbar seems behind other elements

I use a NavigationView in a WindowGroup and inside of the NavigationView a List as a sidebar and an HStack for the content. In addition I use a toolbar with several icons.

It seems, that the toolbar is behind the content. Only when I move the mouse pointer over the toolbar the icons become active.

enter image description here

If I remove the "padding" of the HStack, it becomes obvious.

Where is the correct "place" for the toolbar or which modifier do I need?

Thank you for helping


Swift version 5.5.1

var body: some Scene {
    WindowGroup {
        NavigationView {
            
            List {
                Text("One")
                Text("Two")
            }
            .listStyle(.sidebar)
            
            HStack {
                Text("Hello, world!")
                    .background(Color.gray)
                    .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)
            }
            .padding(.all, 1)
            .toolbar {
                ToolbarItemGroup(placement: .navigation) {
                    
                    Button(action: {
                        NSApp.keyWindow?.firstResponder?.tryToPerform(#selector(NSSplitViewController.toggleSidebar(_:)), with: nil)
                    }, label: {
                        Image(systemName: "sidebar.left")
                            .imageScale(.large)
                    })
                }
            }
        }
        
    }
    .windowStyle(HiddenTitleBarWindowStyle())
}

Upvotes: 1

Views: 353

Answers (0)

Related Questions