SwiftUI动画和随后的反向动画恢复到原始状态

我正在使用SwiftUI,并且我想在视图出现后立即对其进行动画处理(动画的显式类型无关紧要),以便在我的应用中进行演示。 假设我只是想放大视图,然后再次将其缩小到其原始大小,我需要能够将视图动画化为新状态,然后再恢复为原始状态。 这是到目前为止我尝试过的示例代码:

import SwiftUI
import Combine

struct ContentView: View {
    @State private var shouldAnimate = false
    private var scalingFactor: CGFloat = 2    

    var body: some View {
        Text("hello world")
        .scaleEffect(self.shouldAnimate ? self.scalingFactor : 1)
        .onAppear {
            let animation = Animation.spring().repeatCount(1, autoreverses: true)
            withAnimation(animation) {
                self.shouldAnimate.toggle()
            }
        }
    }

Obviously this does not quite fulfill my requirements, because let animation = Animation.spring().repeatCount(1, autoreverses: true) only makes sure the animation (to the new state) is being repeated by using a smooth autoreverse = true setting, which still leads to a final state with the view being scaled to scalingFactor.

So neither can I find any property on the animation which lets my reverse my animation back to the original state automatically (without me having to interact with the view after the first animation), nor did I find anything on how to determine when the first animation has actually finished, in order to be able to trigger a new animation.

我发现将某些View设置为动画非常普遍,例如只是为了展示此视图可以与之交互,但最终不会改变视图的状态。例如,为按钮上的回弹动画效果,最终将按钮设置回其原始状态。当然,我发现了几种建议与按钮交互以触发反向动画回到其原始状态的解决方案,但这不是我想要的。