Animation Error: 'animation' was deprecated in iOS 15.0: Use withAnimation or animation(_:value:) instead.

Hi! I'm working on a feature where when I click on a button, I want to rotate the button continuously until I press it again. The animation works but now I get this error:

'animation' was deprecated in iOS 15.0: Use withAnimation or animation(_:value:) instead.

I've looked online and couldn't find I solution for this particular problem.

This is the code I've used:

struct ContentView: View {

@EnvironmentObject var oD: ObservableData


    var body: some View {

                        Button(action: {
                            print("ButtonAction")
                        }){
                            Image(systemName: (oD.presetsSettings ? "checkmark.circle" : "gear"))
                                .frame(width: 20, height: 20)
                                .animation(.easeInOut(duration: 0.35).delay(0), value: oD.presetsSettings)
                                .rotationEffect((oD.presetsSettings ? .degrees(-10) : .degrees(80)))
                                .animation(.easeInOut(duration: 0.30), value: oD.presetsSettings)
                                .rotationEffect((oD.presetsSettings ? .degrees(-20) : .degrees(20)))
                                .animation(oD.presetsSettings ? .linear(duration: 0.15).repeatForever(autoreverses: true) : .linear(duration: 0.2))
                        }


.

The oD.presetsSettings to what I refer is a Bool, with the standard value of false.

Is there a way to get rid of the 'error'?

Answered by Carrione in 749227022

You forgot to add the value parameter to the third animation modifier.

struct ContentView: View {

@EnvironmentObject var oD: ObservableData


    var body: some View {

                        Button(action: {
                            print("ButtonAction")
                        }){
                            Image(systemName: (oD.presetsSettings ? "checkmark.circle" : "gear"))
                                .frame(width: 20, height: 20)
                                .animation(.easeInOut(duration: 0.35).delay(0), value: oD.presetsSettings)
                                .rotationEffect((oD.presetsSettings ? .degrees(-10) : .degrees(80)))
                                .animation(.easeInOut(duration: 0.30), value: oD.presetsSettings)
                                .rotationEffect((oD.presetsSettings ? .degrees(-20) : .degrees(20)))
                                .animation(oD.presetsSettings ? .linear(duration: 0.15).repeatForever(autoreverses: true) : .linear(duration: 0.2), value: oD.presetsSettings)
                        }
Accepted Answer

You forgot to add the value parameter to the third animation modifier.

struct ContentView: View {

@EnvironmentObject var oD: ObservableData


    var body: some View {

                        Button(action: {
                            print("ButtonAction")
                        }){
                            Image(systemName: (oD.presetsSettings ? "checkmark.circle" : "gear"))
                                .frame(width: 20, height: 20)
                                .animation(.easeInOut(duration: 0.35).delay(0), value: oD.presetsSettings)
                                .rotationEffect((oD.presetsSettings ? .degrees(-10) : .degrees(80)))
                                .animation(.easeInOut(duration: 0.30), value: oD.presetsSettings)
                                .rotationEffect((oD.presetsSettings ? .degrees(-20) : .degrees(20)))
                                .animation(oD.presetsSettings ? .linear(duration: 0.15).repeatForever(autoreverses: true) : .linear(duration: 0.2), value: oD.presetsSettings)
                        }

It works! Thank you!

Animation Error: 'animation' was deprecated in iOS 15.0: Use withAnimation or animation(_:value:) instead.
 
 
Q