I have a heart image/system image that I want to appear by changing the opacity when you tap it two times, but I cannot figure out how to.
import SwiftUI
import PlaygroundSupport
struct ContentView: View{
var body: some View{
Image("apple")
.resizable()
.scaledToFill()
.clipShape(Circle())
.frame(width:200,height:200)
.overlay(
Image(systemName: "heart.fill")
.font(.system(size:50))
.foregroundColor(.red)
.opacity(0)
.onTapGesture(count:2){
}
)
}
}
I expected by tapping on the image two times:
Image(systemName: "heart.fill")
.font(.system(size:50))
.foregroundColor(.red)
.opacity(0)
.onTapGesture(count:2){
opacity(2)
}
it will show the heart, by I cannot change anything
In SwiftUI you generally change the state of a variable
opacityin this example, to change the view. Try this example code to change the opacity (which is 0...1) of the heart when you double tap on it.EDIT-1:
If you want to show the
heartwhen you double tap on the main image, then put theonTapGestureon that image, as shown in the example code. In this example if you double tap on thehouseagain theheartdisappears.