问题描述
我有一个动画背景图像可以在屏幕上水平移动。我导航进行应用内购买,无论是在输入密码之前购买还是取消,当我返回时,背景图像不再动画。如果我在到达要求输入密码的框之前取消,图像仍然是动画。 我怎样才能防止这种情况发生,或者重新启动动画?
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()
}
}
}
}
如果我在这里取消,动画仍然有效:
如果我在此处取消或完成购买,则不再有动画:
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)