简体   繁体   English

SwiftUI 全屏透明按键

[英]SwiftUI full screen transparent button

I try to add full screen transparent button:我尝试添加全屏透明按钮:

Button(action: {
       // my action
}) {
    Rectangle()
     .opacity(0)
}

But in case .opacity() is less than 0.1 button action stop working.但如果.opacity()小于 0.1 按钮操作停止工作。 How to implement full screen transparent button?如何实现全屏透明按钮?

Tested on iOS 14.3(Sim), iOS 14.2(iPhone X), Xcode 12.3在 iOS 14.3(Sim)、iOS 14.2(iPhone X)、Xcode 12.3 上测试

Here is possible solution.这是可能的解决方案。 Tested with Xcode 12.1 / iOS 14.1使用 Xcode 12.1 / iOS 14.1 测试

struct DemoClearButton: View {
    var body: some View {
        Color.clear
            .contentShape(Rectangle())
            .onTapGesture {
                print(">> transparent tapped")
            }
    }
}

Note: probably in place of usage you'd wanted to add .edgesIgnoringSafeArea(.all)注意:可能代替您想要添加的用法.edgesIgnoringSafeArea(.all)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM