我有一個基于macOS xcode swiftui檔案的應用程式。 我可以看到,如果我在應用程式中,"view->show tab bar",我可以免費獲得多個標簽。 然而,如果我做一個 "檔案打開...",它會創建一個新的視窗。 現在我最終發現,在選擇檔案時按住選項會在現有視窗的一個新標簽中打開它。 有誰知道是否有可能將基于檔案的應用程式配置為每次都在新標簽頁而不是新視窗中打開?
uj5u.com熱心網友回復:
好吧,對于任何最終來到這里的人來說。 感謝El Tomato的提示,我已經實作了(大部分)我想要的東西。 關鍵步驟是:
對我來說,makeWindowControllers的代碼是...
let tabsWindow = NSApplication. shared.windows.filter({$0.tabGroup ! = nil}).first
let window = NSWindow(
contentRect: NSRect(x: 0, y: 0, width: 480, height: 300)。)
styleMask: [.titled, .closable, .miniaturizable, .resizable, .fullSizeContentView]。
backing: .buffered, defer: false)
window.isReleasedWhenClosed =false
window.center()
window.contentView = NSHostingView(rootView: contentView)
if tabsWindow != nil {tabsWindow!.addTabbedWindow(window, ordered: .under) }
else { window.toggleTabBar(self) }
uj5u.com熱心網友回復:
在makeWindowControllers()中設定window.tabbingMode為preferred。
override func makeWindowControllers() {
//創建提供視窗內容的SwiftUI視圖。
let contentView = ContentView()
//創建視窗并設定內容視圖。
let window = NSWindow(
contentRect: NSRect(x: 0, y: 0, width: 480, height: 300)。)
styleMask: [.titled, .closable, .miniaturizable, .resizable, .fullSizeContentView]。
backing: .buffered, defer: false)
window.isReleasedWhenClosed =false
window.center()
window.contentView = NSHostingView(rootView: contentView)
window.tabbingMode = .preferred // open new document in tab.
let windowController = NSWindowController(window: window)。
self.addWindowController(windowController)
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/324725.html
標籤:
