如果Button具有buttonStyle,则SwiftUI键盘快捷方式将不起作用

标签 swift swiftui

这有效

Button(action: {
   print("pressed")
}){
   Text("Button")
}
.keyboardShortcut("B", modifiers: .command)
这不是
Button(action: {
   print("pressed")
}){
   Text("Button")
}
.buttonStyle(PlainButtonStyle())
.keyboardShortcut("B", modifiers: .command)
有没有其他人经历过

最佳答案

看起来像个 bug 。但是,如果您使用小写的"b",它将按预期工作:

Button(action: {
    print("pressed")
}) {
    Text("Button")
}
.buttonStyle(PlainButtonStyle())
.keyboardShortcut("b", modifiers: .command)

关于如果Button具有buttonStyle,则SwiftUI键盘快捷方式将不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66356450/

相关文章:

ios - Xcode 12 中的 “Cannot preview in this file - Connection interrupted: send previewInstances message to agent"错误

ios - Swift 2.2 - 记事本应用程序,将单独的 textView 关联到单元格而不添加 ViewController

ios - 我希望 func locationManager(manager : CLLocationManager, didUpdateToLocation 即使在应用程序被终止后也能被调用?

swift - 无法将类型 'Swift._NSContiguousString' 的值转换为“NSNumber”

swift - 如何在没有 PKToolPicker 的情况下使用 PKCanvasView 功能?

ios - 为什么更改状态变量时界面会抽动?

swift - 使用 SwiftUI 预览崩溃 @Binding : communication with the app was interrupted

swift - UITableView - 滚动时选择段时索引超出范围

swift - Xcode 11.2.1-Swift 5-无法将主 Storyboard "Main"更改为另一个 Storyboard "Start"

swift - 在SwiftUI中,如何在ForEach中使用.enumerated()?