我正在嘗試洗掉 macOS 中的所有命令.commandsRemoved(),但效果很好,但我可以看到有些命令沒有被洗掉,例如ShowTabBar或ShowAllTabs:
@main
struct testApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
.commandsRemoved()
}
}

uj5u.com熱心網友回復:
您無法洗掉欄上的應用程式標題選單,但以下內容可以洗掉其下的所有命令。首先,將以下代碼行添加到您的 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
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/534963.html
標籤:迅速苹果系统迅捷
