SwiftUI-WeChat icon indicating copy to clipboard operation
SwiftUI-WeChat copied to clipboard

请教一个问题,如何像js一样阻止事件向上冒泡

Open coder-yubin opened this issue 3 years ago • 1 comments

Simulator Screen Shot - iPod touch (7th generation) - 2021-10-21 at 11 32 52 如上图,怎么让只点击红色背景时才关闭弹出菜单,现在是点击菜单边缘也会关闭 ` 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
            }
        }

`

coder-yubin avatar Oct 21 '21 03:10 coder-yubin

找到了一个不合适的方法解决了此问题,在黑色的弹出菜单上添加onTapGesture { }就可以了

coder-yubin avatar Oct 27 '21 09:10 coder-yubin