【发布时间】:2021-01-17 17:28:59
【问题描述】:
我尝试添加全屏透明按钮:
Button(action: {
// my action
}) {
Rectangle()
.opacity(0)
}
但如果.opacity() 小于 0.1 按钮操作停止工作。如何实现全屏透明按钮?
在 iOS 14.3(Sim)、iOS 14.2(iPhone X)、Xcode 12.3 上测试
【问题讨论】:
我尝试添加全屏透明按钮:
Button(action: {
// my action
}) {
Rectangle()
.opacity(0)
}
但如果.opacity() 小于 0.1 按钮操作停止工作。如何实现全屏透明按钮?
在 iOS 14.3(Sim)、iOS 14.2(iPhone X)、Xcode 12.3 上测试
【问题讨论】:
这是可能的解决方案。使用 Xcode 12.1 / iOS 14.1 测试
struct DemoClearButton: View {
var body: some View {
Color.clear
.contentShape(Rectangle())
.onTapGesture {
print(">> transparent tapped")
}
}
}
注意:可能你想添加.edgesIgnoringSafeArea(.all)
【讨论】:
Color.clear 动作不执行,任何其他颜色都完美。