I have built a screen very similar to the Tinder main screen. I have set the borders on the draggable icon and the next card loads by being animated from the top of the screen. At the moment there are 2 buttons (1 accept button, 1 reject button) and when they are pressed the card rotates and transforms out of the screen in the right direction. This function currently accomplishes this animation...
func rejectAnimation() {
let scale = CGAffineTransformMakeScale(1, 1)
let translate = CGAffineTransformMakeTranslation(0, 0)
self.cardUIView.transform = CGAffineTransformConcat(scale, translate)
springWithCompletion(0.75, animations: {
let rotate = CGAffineTransformMakeRotation(CGFloat(-M_PI_2))
let translate = CGAffineTransformMakeTranslation((-375), 0)
self.cardUIView.transform = CGAffineTransformConcat(rotate, translate)
}, completion: { finished in 0
self.refreshView()
})
}
and
func acceptAnimation() {
let scale = CGAffineTransformMakeScale(1, 1)
let translate = CGAffineTransformMakeTranslation(0, 0)
self.cardUIView.transform = CGAffineTransformConcat(scale, translate)
springWithCompletion(0.75, animations: {
let rotate = CGAffineTransformMakeRotation(CGFloat(M_PI_2))
let translate = CGAffineTransformMakeTranslation(375, 0)
self.cardUIView.transform = CGAffineTransformConcat(rotate, translate)
}, completion: { finished in 0
self.refreshView()
})
}
My question is this. How can I animate so that when the user drags a card and drops it to the outside the right or left boundaries the card continues to translate off the screen in the direction it was swiped before resetting to a new card?
Note: the springWithCompletion is a function that performs the animations within it over a certain period of time.