我想为孩子们做一个迷你游戏,让字母字符漂浮在气泡内,所以我使用了文本与覆盖图像,它的工作,但问题是,当我点击气泡时,我不知道如何使它消失的动画,并使文本停止在当前位置
struct ExtractedView: View {
@State var BubbleAnimate = false
@State var AlphbetArray: [String] = ["A", "B","C","D","E","F","G"]
@State var randomNumber = Int.random(in: 0...6)
var body: some View {
Button {
BubbleAnimate = true
print("Hi")
} label: {
Text("Test Me")
}
.offset(x:100)
Text(AlphbetArray[randomNumber])
.font(.system(size: 120))
.fontWeight(.bold)
.foregroundColor(.purple)
.padding()
.overlay {
Image("bubble").resizable().frame(width: 130.0, height: 130.0).scaledToFit()
}
.animation(.linear(duration: 5).repeatForever(autoreverses: false), value: BubbleAnimate)
.offset(y:BubbleAnimate ? -300 : 300)
.onTapGesture {
print("Hello")
BubbleAnimate.toggle()
// I tried toggle but it won't work probably
}
}
}
这就是我怎样才能使气泡消失的动画,并使字母停留1秒的时间,使更多的动画,如缩放等结果...
1条答案
按热度按时间oknwwptz1#
有几点考虑:
.transition()
修改器设置其动画。下面是代码: