在SwiftUI中,有没有一种方法可以通过长按手势显示上下文菜单?
我有这样的一个代码:
Text(messageModel.message)
.padding(.vertical,8)
.padding(.horizontal,12)
.background(Constants.clientMessageColor)
.foregroundColor(Color.black)
.cornerRadius(20, corners: [.topLeft,.bottomLeft,.topRight, .bottomRight])
.onTapGesture {
self.isExpanded.toggle()
self.isClientNameVisible.toggle()
}
.contextMenu {
Button(action: {
}) {
Text("Normal Colors")
Image(systemName: "paintbrush")
}
}
还有我在SwiftUI中使用Menu,但不知道如何在长按时显示。
我的代码看起来像这样:
Menu() {
Button("Order Now", action: {})
Button("Adjust Order", action: {})
Button("Cancel", action: {})
} label : {
Text("HELLO")
.onLongPressGesture {
// Show menu when this triggers
}
}