How can I achieve the Tinder effect in Swift?
I mean, I have an image and I want to accept if I swipe to the right and deviate if I swipe to the left.
I can do this with the code below:
@IBAction func SwipeRight(sender: UISwipeGestureRecognizer) { UIView.animateWithDuration(1) { self.Imagem.center = CGPointMake(self.Imagem.center.x - 150, self.Imagem.center.y ) }
and
@IBAction func SwipeLeft(sender: UISwipeGestureRecognizer) { UIView.animateWithDuration(1) { self.Imagem.center = CGPointMake(self.Imagem.center.x + 150, self.Imagem.center.y ) }
But in this way, the user cannot undo the action. I want that if the user moves the distance of the delta from the edge (left or right), an image appears that allows the user now, if he finishes the movement, the action will be performed. Otherwise, the user can, without stopping the movement, return to a greater distance than the delta, and the action will be canceled.
source share