正如标题所建议的,我应该如何在 macOS 上使用 SwiftUI 2 禁用全屏按钮?
我能找到的唯一信息似乎是使用来自 NSWindow
的功能.在 SwiftUI 2 中是否有一种本地方法可以做到这一点?
最佳答案
你可以简单地使用.onReceive
修饰符来达到目的:
struct MacApp: App {
var body: some Scene {
WindowGroup {
ContentView()
.frame(width: 480, height: 272)
.fixedSize()
.onReceive(NotificationCenter.default.publisher(for: NSApplication.willUpdateNotification), perform: { _ in
for window in NSApplication.shared.windows {
window.standardWindowButton(.zoomButton)?.isEnabled = false
}
})
}
.windowStyle(HiddenTitleBarWindowStyle())
}
关于swift - 如何在 macOS 上使用 SwiftUI 2 禁用全屏按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65858882/