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?