在 AppKit 中,當使用鍵盤快捷鍵時,按鈕會在使用快捷鍵時直觀地按下。在 SwiftUI 中, usingkeyboardShortcut(_:modifiers:)有效,但按鈕上沒有指示。
另外,我似乎記得在某處讀過 usingkeyboardShortcut(_:modifiers:)將修飾符添加到按鈕(“按(? D)”)。那只是選單嗎?
struct ContentView: View {
var body: some View {
Button("Press") {
print("pressed")
}
.keyboardShortcut("d", modifiers: .command)
.padding()
}
}
同樣,這有效,但使用快捷方式時沒有按下指示。
uj5u.com熱心網友回復:
使用大寫的“D”,例如
Button("Press") {
print("pressed")
}
.keyboardShortcut("D") // << here !!
使用 Xcode 13.4 / macOS 12.4 測驗
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/494672.html
上一篇:防止macOS欄有側邊欄
