I am trying to animate playing cards between UIStackViews and have spent countless hours trying to get it right. I feel this should be pretty straight forward, but I haven't found any information to help me.
Clip here: https://pixlig.se/animate.mov
The idea here is to make things look as natural as possible, i.e. the cards picked should animate from their origin to (the bottom of) the stock cards.
The code that produces the result in the clip is the following.
func collectCards(_ cards: Array<Card>, player: Player) {
var delay = 0.5
var cardPoints = 0
// Loop through collected cards, insert them in stock and remove them from table hand
for card in cards {
UIView.animate(withDuration: 0.3, delay: delay, options: [], animations: {
card.frame.origin = card.origin
}, completion: { (finished: Bool) -> Void in
//player.stock.insert(card, at: 0)
})
player.stock.insert(card, at: 0)
tableCards.hand.remove(at: tableCards.hand.index(of: card)!)
cardPoints += card.getCardPoints(card)
delay += 0.1
}
}
Now, card.origin
get's its CGPoint when the card is tapped like so:
card.origin = view.convert(card.frame.origin, to: player1.stockView)
and that's where I'm doing it wrong I guess. All I want is the distance from the tapped card to the end position. So am I going about this the wrong way?
If you want to take a closer look at the whole project you can find it here: https://github.com/matsmorot/Smulle