【问题标题】:How can I remove all commands in macOS?如何删除 macOS 中的所有命令?
【发布时间】:2022-11-16 12:30:55
【问题描述】:

我正在尝试在 .commandsRemoved() 的帮助下删除 macOS 中的每个命令,这做得很好,但我可以看到有些命令没有被删除,比如显示标签栏或者显示所有选项卡:

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

【问题讨论】:

    标签: swift macos swiftui


    【解决方案1】:

    您无法删除栏上的应用程序标题菜单,但以下内容可以删除其下的所有命令。首先,将以下代码行添加到您的 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

    【讨论】:

      猜你喜欢
      • 2021-05-25
      • 2012-01-15
      • 2010-10-06
      • 1970-01-01
      • 2020-12-26
      • 2023-03-21
      • 2016-02-04
      • 2014-02-04
      • 2017-12-15
      相关资源
      最近更新 更多