Swift 点击时如何停止动画
我正在做一个踢踏游戏,这是带有动画的按钮。这是非常缓慢,我想加快它,所以当用户点击,它将重置动画和计数点击 目前,它的速度很慢,如果在动画仍在进行时再次点击,它将错过点击Swift 点击时如何停止动画,swift,animation,uibutton,Swift,Animation,Uibutton,我正在做一个踢踏游戏,这是带有动画的按钮。这是非常缓慢,我想加快它,所以当用户点击,它将重置动画和计数点击 目前,它的速度很慢,如果在动画仍在进行时再次点击,它将错过点击 @IBAction func slimeTap(_ sender: UIButton) { tapCount += tapIncrease checkLevel(tapCount) UIView.animate(withDuration: 0.03, animations: { //sh
@IBAction func slimeTap(_ sender: UIButton) {
tapCount += tapIncrease
checkLevel(tapCount)
UIView.animate(withDuration: 0.03, animations: {
//shrink
self.playSound()
sender.transform = CGAffineTransform(scaleX: 0.8, y: 0.8)
}, completion: {_ in
//change it back to how it was
//grow
UIView.animate(withDuration: 0.05, animations: {
sender.transform = CGAffineTransform(scaleX: 1, y: 1)
})
})
}
尝试添加
.layer.removeAllAnimations()
以删除该层上的任何现有动画,并将.allowUserInteraction
作为动画选项以启用和注册用户点击事件:
@IBAction func slimeTap(uu发送方:ui按钮){
抽头计数+=抽头增加
检查级别(抽头计数)
resizingView.layer.removeAllAnimations()的大小
UIView.animate(持续时间:0.3,延迟:0,选项:[.allowUserInteraction],动画:{
self.playSound()
sender.transform=CGAffineTransform(scaleX:0.8,y:0.8)
}){in
UIView.animate(持续时间:0.5,延迟:0,选项:[.allowUserInteraction],动画:{
sender.transform=CGAffineTransform(scaleX:1,y:1)
})
}
}
尝试添加.layer.removeAllAnimations()
以删除该层上的任何现有动画,并将.allowUserInteraction
作为动画选项以启用和注册用户点击事件:
@IBAction func slimeTap(uu发送方:ui按钮){
抽头计数+=抽头增加
检查级别(抽头计数)
resizingView.layer.removeAllAnimations()的大小
UIView.animate(持续时间:0.3,延迟:0,选项:[.allowUserInteraction],动画:{
self.playSound()
sender.transform=CGAffineTransform(scaleX:0.8,y:0.8)
}){in
UIView.animate(持续时间:0.5,延迟:0,选项:[.allowUserInteraction],动画:{
sender.transform=CGAffineTransform(scaleX:1,y:1)
})
}
}
那么,您是希望加快动画速度,还是在点击时停止动画?这是两件截然不同的事情。点击时停止动画。这样,点击按钮将注册更多点击,因为动画将结束。当前,它在点击时正在处理动画,而不是注册所有点击。您忘记了,您是希望加快动画速度,还是在点击时停止动画?这是两件截然不同的事情。点击时停止动画。这样,点击按钮将注册更多点击,因为动画将结束。目前,它正在处理点击时的动画,而不是注册您忘记的所有点击