I'm using the simplified code below to create a window with 4 split view items, some of them collapsed. I would expect the title bar to be transparent since I'm using window.titlebarAppearsTransparent = true, but it seems that this particular view configuration causes the title bar to be visible until I collapse and expand the sidebar again.
Removing any of the split view items, uncollapsing any of them, or changing the view of any of the view controllers, causes the title bar to be consistently visible or hidden, although I don't understand the logic, since I'm telling the window that it should be transparent.
When launching the app in light mode, it's more difficult to notice the issue since the title bar background is equal to the content background and only the separator is visible (even though the code sets window.titlebarSeparatorStyle = .none):
After collapsing and expanding the sidebar, the separator is gone:
In dark mode the title bar is more visible:
After collapsing and expanding the sidebar, the title bar background and separator are gone:
I created FB20306872.
@main
class AppDelegate: NSObject, NSApplicationDelegate, NSToolbarDelegate {
var splitViewController: NSSplitViewController!
func applicationDidFinishLaunching(_ aNotification: Notification) {
let splitViewItem1 = NSSplitViewItem(sidebarWithViewController: ViewController1())
let splitViewItem2 = NSSplitViewItem(viewController: ViewController2())
let splitViewItem3 = NSSplitViewItem(viewController: NSViewController())
splitViewItem3.isCollapsed = true
let splitViewItem4 = NSSplitViewItem(viewController: NSViewController())
splitViewItem4.isCollapsed = true
splitViewController = NSSplitViewController()
splitViewController.splitViewItems = [splitViewItem1, splitViewItem2, splitViewItem3, splitViewItem4]
let window = NSWindow(contentViewController: splitViewController)
window.styleMask = [.titled, .closable, .miniaturizable, .resizable, .fullSizeContentView]
window.titlebarAppearsTransparent = true
let toolbar = NSToolbar(identifier: "")
toolbar.delegate = self
toolbar.displayMode = .iconOnly
window.toolbar = toolbar
window.titlebarSeparatorStyle = .none
window.makeKeyAndOrderFront(nil)
}
func toolbarAllowedItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] {
return [.space, .flexibleSpace, .sidebarTrackingSeparator, .init("item")]
}
func toolbarDefaultItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] {
return [.init("item"), .sidebarTrackingSeparator]
}
func toolbar(_ toolbar: NSToolbar, itemForItemIdentifier itemIdentifier: NSToolbarItem.Identifier, willBeInsertedIntoToolbar flag: Bool) -> NSToolbarItem? {
switch itemIdentifier.rawValue {
case "item":
let item = NSToolbarItem(itemIdentifier: itemIdentifier)
item.image = NSImage(systemSymbolName: "sidebar.leading", accessibilityDescription: nil)
item.action = #selector(toggleSidebar(_:))
item.target = self
return item
default:
return nil
}
}
@objc func toggleSidebar(_ sender: Any?) {
splitViewController.splitViewItems[0].animator().isCollapsed = !splitViewController.splitViewItems[0].isCollapsed
}
}
class ViewController1: NSViewController {
override func loadView() {
view = NSView(frame: CGRect(x: 0, y: 0, width: 300, height: 200))
}
}
class ViewController2: NSViewController {
override func loadView() {
let textView = NSTextView()
let scrollView = NSScrollView(frame: CGRect(x: 0, y: 0, width: 400, height: 200))
scrollView.hasVerticalScroller = true
scrollView.documentView = textView
view = scrollView
}
}