I am attempting to allow one tap gesture to trigger different views that are in a ZStack. When I tap on the red square that is superimposed on the yellow square, I would like both to react to the touch.
So if I tap on the red square, I should receive the printout "Red rectangle tapped" and "Yellow rectangle tapped". And not only "Red rectangle tapped".
Is there any easy way to do this?
struct MultiTouchView: View {
var body: some View {
ZStack(alignment: .center) {
Rectangle()
.foregroundColor(.yellow).opacity(0.3)
.onTapGesture {
print("Yellow rectangle tapped")
}
Rectangle()
.foregroundColor(.red)
.frame(width: 200, height: 200)
.onTapGesture {
print("Red rectangle tapped") // -> I would like this tap to react but also to allow the yellow rectangle to react to the same tap
}
}
}
}