【问题标题】:How can i remove the "New window" option in macOS SwiftUI App?如何删除 macOS SwiftUI App 中的“新窗口”选项?
【发布时间】:2021-12-12 11:28:17
【问题描述】:

I need to remove this option in my app

这是我的应用委托:

import AppKit
public class AppDelegate: NSObject, NSApplicationDelegate {
    public func applicationWillTerminate(_ aNotification: Notification) {
        MainViewModel.shared.saveSettings()
    }
    public func applicationDidFinishLaunching(_ notification: Notification) {
        for window in NSApp.windows {
            var style = window.styleMask
            style.remove(.resizable)
            window.styleMask = style
            window.standardWindowButton(.zoomButton)?.isHidden = true
        }
    }
    public func applicationWillFinishLaunching(_ notification: Notification) {
        NSWindow.allowsAutomaticWindowTabbing = false
    }
}

我该怎么做?

【问题讨论】:

  • 请编辑问题以将其限制为具有足够详细信息的特定问题,以确定适当的答案。

标签: macos swiftui appkit


【解决方案1】:

只需将 commands 修饰符添加到 WindowGroup,如下所示:

WindowGroup {
            MainView().frame(width: 300, height: 95)
        }.commands {
            CommandGroup(replacing: CommandGroupPlacement.newItem) {
            }
        }

【讨论】:

    猜你喜欢
    • 2021-07-24
    • 2022-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-26
    • 2023-02-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多