Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
coder-yubin opened this issue Oct 21, 2021 · 1 comment
Open

Comments

@coder-yubin
Copy link

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant