Here are coin collecting animation code. Code is animate the image in timer.
func animateCoin() {
count = count + 1
let moneyView = UIImageView(image: UIImage(named: "Your image name"))
moneyView.frame = CGRect(x: 100, y: self.view.frame.size.height - 350, width: 100, height: 100)
view.addSubview(moneyView)
UIView.animate(withDuration: 1.0, animations: {
moneyView.frame.origin.x = 250
moneyView.frame.origin.y = 100
AudioServicesPlaySystemSound(1122)
}) { _ in }
}
func startCoinAnimation() {
Timer.scheduledTimer(withTimeInterval: 0.1, repeats: true) { timer in
self.animateCoin()
if self.count == 10 {
timer.invalidate()
self.count = 0
}
}
}
Here is Demo link how animation look : https://www.youtube.com/watch?v=GR9hIpNeL-U