iOS 15.0 中已弃用“animation”

Mic*_*ael 8 animation swift swiftui

我使用了一个非常简单的动画,以非常柔和流畅的方式打开按钮栏:

.animation(.spring(response:1.5))
Run Code Online (Sandbox Code Playgroud)

我想将我的应用程序更新到 iOS15,但“动画”在 iOS 15.0 中已被弃用

所以我尝试将动画更改为:

.animation(.spring(response:1.5), value: 0)
Run Code Online (Sandbox Code Playgroud)

或类似的东西:

 .animation(.spring(response: 1.5, dampingFraction: 2.5, blendDuration: 2.5), value: 10)
Run Code Online (Sandbox Code Playgroud)

但是新的动画弹出的速度非常快,流畅的效果没有了。

有谁知道如何将我的小弹簧动画带到 iOS 15 上?

Geo*_*e_E 19

当使用animation修饰符 with时value,动画更改运行。value

例如,如果在切换布尔值时触发动画,您将执行以下操作:

@State private var showThing = false

/* ... */

.animation(.spring(response: 1.5), value: showThing)
Run Code Online (Sandbox Code Playgroud)

运行时showThing.toggle(),你会看到这个动画生效。

文档animation(_:value:)

当指定值更改时,将给定动画应用于此视图。

animation每当更改时都会应用到此视图的视图value

value:监视变化的值。