I'm trying to make an animation where the coin flips and moves up then back down and stops after button click. With this code it moves up and down, but then snaps to the top position after the animation finishes. I know it must be because of the '.offset' but I don't know a way around it. Youtube hasn't been much help.
@State private var isClicked : Bool = false
Image(coins[numbers[0]])
.resizable()
.scaledToFit()
.scaleEffect(0.6)
.rotation3DEffect(isClicked ?
.init(degrees: 1080) : .init(degrees: 0),
axis: (x: 10.0, y: 0.0, z: 0.0))
.animation(Animation.easeInOut.repeatCount(2, autoreverses: true)
.speed(0.5))
.offset(y: isClicked ? -200 : 0)
Button(action: {self.animation()}, label: {
Text("FLIP!")
.aspectRatio(contentMode: .fit)
.foregroundColor(Color.black)
})
func animation() {
self.isClicked.toggle()
}