如何在应用内购买后重新启动动画?

问题描述

我有一个动画背景图像可以在屏幕上水平移动。我导航进行应用内购买,无论是在输入密码之前购买还是取消,当我返回时,背景图像不再动画。如果我在到达要求输入密码的框之前取消,图像仍然是动画。 我怎样才能防止这种情况发生,或者重新启动动画?

struct Home: View {
    @State private var animateBackground = false
    var body: some View {
        ZStack {

            imagebackgroundView(gameSettings: self.gameSettings,animate: self.animateBackground)
            
            //more code...
        }
    }
}

struct imagebackgroundView: View {
    
    @Observedobject var gameSettings: GameSettings
    @State var animate: Bool
    
    let animation: Animation = Animation.linear(duration: 100.0).repeatForever(autoreverses: false)
    
    var body: some View {
        GeometryReader { geo in
            HStack(spacing: -1) {
                Image("\(AppConstants.levels[gameSettings.gameLevel].background)")
                    .resizable()
                    .scaledToFill()
                    .frame(height: geo.size.height)

                Image("\(AppConstants.levels[gameSettings.gameLevel].background)")
                    .resizable()
                    .scaledToFill()
                    .frame(width: geo.size.width,height: geo.size.height,alignment: .leading)
            }
            .frame(width: geo.size.width,alignment: animate ? .trailing : .leading)
        }
        .ignoresSafeArea()
        .onAppear {
            withAnimation(animation) {
                animate.toggle()
            }
        }
    }
}

如果我在这里取消,动画仍然有效:

enter image description here

如果我在此处取消或完成购买,则不再有动画:

enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...