How do I animate an image in SwiftUI?

Hello everyone, help me figure out how to make a picture fall from top to bottom when you click on the button, it was of different sizes (for example: 64x64, 128x128) and fell not only in the center, but in different places on the screen?

Also, I would like to know how to make sure that, for example, when upgrading for 100 points, the counter itself counts +1, +10, +100 and so on every second, and, accordingly, auto-animation of the falling image.

I want to make a Cookie Clicker type for myself, but I'm just learning.

@State var Count: Int = 0

var body: some View {
    ZStack {

        VStack {
            Text("\(Count) Cookies")

        Button(action: {
            self.Count += 1
        }) {
            Image("cookie").renderingMode(.original)
            .resizable()
            .frame(width: 128, height: 128)
            }
        }
    }
}
Author: Seplaz, 2020-04-07

2 answers

UIView animate

Animate

Check out these links. They will give you the base and you can redo it as you need. There is too much question in this post. You'd better split them up into several posts.

 0
Author: JiosDev, 2020-06-12 12:52:24

I found a way to make the animation of reducing the button when pressed, and how to make it return to its original state after reducing it?

VStack {
    Text("\(Count) Cookies")

    Button(action: {
        withAnimation(.easeInOut(duration: 1)) {
            self.Count += 1
            self.buttonScale = 0.5
        }
    }) {
        Image("cookie").renderingMode(.original)
                .resizable()
                .frame(width: 128, height: 128)
                .shadow(radius: 3)
                .scaleEffect(self.buttonScale)
    }
}
 0
Author: Seplaz, 2020-05-12 00:01:48