簡體   English   中英

如何刪除 macOS 中的所有命令?

[英]How can I remove all commands in macOS?

我試圖在.commandsRemoved()的幫助下刪除 macOS 中的每個命令,這做得很好,但我可以看到有些命令沒有被刪除,比如ShowTabBarShowAllTabs

@main
struct testApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
        .commandsRemoved()
    }
}

在此處輸入圖像描述

您無法刪除欄上的應用程序標題菜單,但以下內容可以刪除其下的所有命令。 首先,將以下代碼行添加到您的 App struct中:

@NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate

然后,創建一個名為 AppDelegate 的新文件(或您記得的任何名稱 - 這也可以位於同一文件中)。 創建一個AppDelegate

//In the file, you must import `AppKit`

class AppDelegate: NSObject, NSApplicationDelegate {
    func applicationWillFinishLaunching(_ notification: Notification) {
            NSWindow.allowsAutomaticWindowTabbing = false //<-- This is the key!

            //This will hide all of the fullscreen and tab menu controls
        
    }
}

此代碼已使用 Xcode 14 和 macOS 13 進行了測試。

參考

https://www.hackingwithswift.com/forums/swiftui/what-s-the-swiftui-way-to-do-this-appdelegate-thing/10559

https://stackoverflow.com/a/65634944/20384561

https://developer.apple.com/documentation/appkit/nswindow/1646657-allowsautomaticwindowtabbing

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM