import SwiftUI
struct ContentView: View {
var body: some View {
ZStack {
Rectangle().fill(Color.blue).frame(width: 300, height: 300).onTapGesture(perform: {
print("Tap rectangle!")
})
// Circle().fill(Color.red).frame(width: 300, height: 300).onTapGesture {
// print("Tap circle!")
// }
// Circle().fill(Color.red).frame(width: 300, height: 300).onTapGesture {
// print("Tap circle!")
// }.allowsHitTesting(false)
Circle().fill(Color.red).frame(width: 300, height: 300).contentShape(Rectangle()).onTapGesture {
print("Tap circle!")
}
}
}
}
import SwiftUI
struct ContentView: View {
var body: some View {
VStack {
Text("Hello")
Spacer().frame(height:100)
Text("World")
}
.contentShape(Rectangle())
.onTapGesture {
print("VStack is clicked!")
}
}
}