SwiftUI-WeChat
SwiftUI-WeChat copied to clipboard
请教一个问题,如何像js一样阻止事件向上冒泡
如上图,怎么让只点击红色背景时才关闭弹出菜单,现在是点击菜单边缘也会关闭
`
if commonData.isPopupMenuShow{
VStack(alignment:.trailing, spacing:0){
HStack{
Spacer()
topArrow
.offset(x: -16, y: 0)
}
VStack(alignment: .center, spacing: 10){
Button("按钮1"){ }
Button("按钮2"){ }
Button("按钮3"){ }
}
.padding(.horizontal,10)
.padding(.vertical,15)
.frame(width: 100)
.background("#333333".toColor())
.foregroundColor(Color.white)
.cornerRadius(10)
Spacer()
}
.background(Color.init(.sRGB, red: 0.8, green: 0.1, blue: 0.1, opacity: 0.5))
.offset(x:-5,y: 0)
.zIndex(2)
.onTapGesture {
commonData.isPopupMenuShow = false
}
}
`
找到了一个不合适的方法解决了此问题,在黑色的弹出菜单上添加onTapGesture { }就可以了