-1

I would like to make the star.png move to the left, return to the starting point, and move to the right repeatedly. I have tried to add .animation(Animation.linear.speed(0.1)), it worked, but it showed 'animation' was deprecated in iOS 15.0: Use withAnimation or animation(_:value:) instead.

Here's my code:

struct CloudView: View {
    @State var show = true
    @State private var scaleValue: CGFloat = 1
    
    var body: some View {
        HStack {
            if show {
                Image(uiImage: UIImage(named: "star.png")!)
                    .resizable()
                    .aspectRatio(contentMode: .fit)
                    .frame(width: 300, height: 300)
                    .padding(.top, -670)
                    .offset(x: -270)
                    .transition(.move(edge: .leading))
                    .animation(Animation.linear.speed(0.05).repeatForever(autoreverses: false))
            }
        }
        .onAppear {
            withAnimation(.spring()) {
                self.show.toggle()
            }
            self.show = true
        }
    }
}

How to avoid this caution?

kkk
  • 187
  • 8
  • Does this answer your question? [How to replace deprecated .animation() in SwiftUI?](https://stackoverflow.com/questions/69443588/how-to-replace-deprecated-animation-in-swiftui) – stackich Apr 09 '23 at 00:33

1 Answers1

0

You can just use the new animation(_:value:) to avoid the warning. Pretty much the new animation is applying the 'animation' to this Image view when it detects whatever you put as 'value' changes. Apple's documentation on Animation