首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

仿finder toolbar

仿finder toolbar

Finder and Notes have a peculiar behaviour that I am seeking to reproduce. The ‘flexible space’ in the NSToolbar seems to take the dimensions of the split view into account. For instance, the first group of buttons aligns on the left side with the right side of the sidebar. The second group of icons aligns with the right side of the first column. When I widen the sidebar, the toolbar items move along with it.

Is it possible to reproduce this?

Solution With the solution provided by @KenThomases, I have implemented this as follows: final class MainWindowController: NSWindowController {

override func windowDidLoad() {

super.windowDidLoad()

window?.toolbar?.delegate = self

// Make sure that tracking is enabled when the toolbar is completed

DispatchQueue.main.async {

self.trackSplitViewForFirstFlexibleToolbarItem()

}

}

}

extension MainWindowController: NSToolbarDelegate {

func toolbarWillAddItem(_ notification: Notification) {

// Make sure that tracking is evaluated only after the item was added

DispatchQueue.main.async {

self.trackSplitViewForFirstFlexibleToolbarItem()

}

}

func toolbarDidRemoveItem(_ notification: Notification) {

trackSplitViewForFirstFlexibleToolbarItem()

}

/// - Warning: This is a private Apple method and may break in the future.

func toolbarDidReorderItem(_ notification: Notification) {

trackSplitViewForFirstFlexibleToolbarItem()

}

/// - Warning: This method uses private Apple methods that may break in the future.

fileprivate func trackSplitViewForFirstFlexibleToolbarItem() {

guard var toolbarItems = self.window?.toolbar?.items, let splitView = (contentViewController as? NSSplitViewController)?.splitView else {

return

}
返回列表