The .animation()
modifier has been deprecated in iOS 15, but I’m not sure I understand how Xcode’s suggested equivalent, animation(_:value:)
, works.
.animation(.easeInOut(duration: 2)) // ⚠️'animation' was deprecated in iOS 15.0: Use withAnimation or animation(_:value:) instead.
How would I change my code to get rid of the warning?
5
Answers
.animation
now takes a second argument calledvalue
.https://developer.apple.com/documentation/swiftui/view/animation(_:value🙂
You need tell Xcode what exactly should be animated! With given a variable that conform to Equatable protocol. That could be State or Binding or any other wrapper that allow you to update the value of it.
Example:
Result:
Another approach would be to embed ontapGesture in a withAnimation
You can also use the animation by using a boolean as the value.
Example Below:
When you tap the CardView(), it will toggle show which in turn will animate the offset both ways.
UUID
refs
https://developer.apple.com/forums/thread/688947