I am showing an image from Assets and this is the code:
struct ImageTest: View {
var body: some View {
ZStack {
Image("testImage")
.resizable()
.scaledToFill()
.frame(width:400)
.frame(height:400)
.clipped()
.border(.red)
.onTapGesture {
print("TAPPED (Date())")
}
}
}
}
Problem:
Image is landscape. I am able to make it scale to fill, but, after clipping it the clipped portion of the image still triggers the on tap action. So, my expectation was to NOT be able to trigger the on tap gesture while outside the square red border (the area I clip the image in…). When I tap to the left or right of the red square, the on tap still triggers.
How can I make it so the clipped area is respected even in the tap action? In other works, I want the image to truly be clipped and affect nothing else once clipped.