Swift 如何仅在长按手势快捷界面上打开菜单
有没有办法在SwiftUI中显示长按手势的关联菜单 我有这样一个代码:Swift 如何仅在长按手势快捷界面上打开菜单,swift,swiftui,Swift,Swiftui,有没有办法在SwiftUI中显示长按手势的关联菜单 我有这样一个代码: Text(messageModel.message) .padding(.vertical,8) .padding(.horizontal,12) .background(Constants.clientMessageColor) .foregroundColor(Color.black) .cornerRadius(20, corners: [.topLeft,.bottomLeft,.topRight
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")
}
}
Menu() {
Button("Order Now", action: {})
Button("Adjust Order", action: {})
Button("Cancel", action: {})
} label : {
Text("HELLO")
.onLongPressGesture {
// Show menu when this triggers
}
}
而且我在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")
}
}
Menu() {
Button("Order Now", action: {})
Button("Adjust Order", action: {})
Button("Cancel", action: {})
} label : {
Text("HELLO")
.onLongPressGesture {
// Show menu when this triggers
}
}
下面是一个简单的演示(为了清晰起见,menuItems
在正文
之外提取):
下面是一个简单的演示(为了清晰起见,menuItems
在正文
之外提取):