我正在编写一个 MacOS 应用程序。我正在显示一个按钮。当应用程序处于非活动状态时,如果我单击按钮,按钮的点击事件将在窗口激活的同时触发。到目前为止,一切都很好。
但是,如果我现在添加.buttonStyle(PlainButtonStyle())
到所需外观的按钮,则当窗口处于非活动状态时不会点击它。第一次单击会激活窗口,我需要第二次单击才能触发按钮。
Button {
print("tapped!")
} label: {
Image(systemName: "doc.on.doc")
.resizable()
.frame(width: 14, height: 14)
.padding(5)
}
.buttonStyle(PlainButtonStyle())