So I want to animate an image in SwiftUI: after a user taps it, the image should be highlighted in a coloraturas (red or green, to indicate if the user tapped the right one). But after a few seconds it should go back to normal - aka as it looked at the start.
I also tried to make a custom highlight button which would've worked too, but it looks like it won't animate...
Currently I use a ZStack
that animates a Color
overlay if the user taps it, but I can't get a completion or something like that can I? How can I 'undo' the animation without user-interaction?
@State var redAlpha = 0.0
var badImg: some View{
ZStack{
Image(badImgName)
.resizable()
.scaledToFit()
Button(action: {
withAnimation {
self.redAlpha = 0.5
}
}) {
Color.clear
}
Color.red.opacity(self.redAlpha) //<--overlay
}
}