简体   繁体   English

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

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

I am trying to remove every commands in macOS with help of .commandsRemoved() which is doing good job, but I can see there is some that did not get removed like ShowTabBar or ShowAllTabs :我试图在.commandsRemoved()的帮助下删除 macOS 中的每个命令,这做得很好,但我可以看到有些命令没有被删除,比如ShowTabBarShowAllTabs

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

在此处输入图像描述

You cannot remove the app title menu on the bar, but the following will work to remove all of the commands under it.您无法删除栏上的应用程序标题菜单,但以下内容可以删除其下的所有命令。 First, add the following line of code to your App struct :首先,将以下代码行添加到您的 App struct中:

@NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate

Then, create a new file called AppDelegate (or whatever you will remember - this can also be in the same file).然后,创建一个名为 AppDelegate 的新文件(或您记得的任何名称 - 这也可以位于同一文件中)。 Create an 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
        
    }
}

This code was tested with Xcode 14 and macOS 13.此代码已使用 Xcode 14 和 macOS 13 进行了测试。

References参考

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

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM