cyr*_*ril 5 appkit swift swiftui
我正在尝试使用全局键盘快捷键以编程方式在 macOS 上的 Swift 中打开 MenuBarExtra。我已经设置了键盘快捷键的所有代码,但我不知道如何使用 SwiftUI 显示/隐藏 MenuBarExtra。在本机 SwiftUI 中是否有一种我似乎找不到的方法?否则,有没有办法通过 AppKit 做到这一点?
我通过以下方式定义了我的菜单栏应用程序:
MenuBarExtra("Title", image: "sample_icon", content: {
ContentView()
.preferredColorScheme(.dark)
})
Run Code Online (Sandbox Code Playgroud)
小智 0
以下对我有用:
我正在使用 HotKey ( https://github.com/soffes/HotKey )
我的 keyUpHandler 看起来像这样:
{
let statusItem = NSApp.windows.first?.value(forKey: "statusItem") as? NSStatusItem
statusItem?.button?.performClick(nil)
}
Run Code Online (Sandbox Code Playgroud)
适用于 .menu 和 .window menuBarExtraStyle
| 归档时间: |
|
| 查看次数: |
498 次 |
| 最近记录: |