Tinder-Like Swipe Animation for iOS

14,888

Solution 1

I built a simpler and more comprehensive project based on that tutorial. In particular, you could use an array of images and assign each card an image based on the index of the image. Will the images be dynamic or static?

Might not help at this point, but here it is anyway: https://github.com/cwRichardKim/TinderSimpleSwipeCards

Solution 2

check this out , written in swift 4

https://github.com/nickypatson/TinderSwipeView

func beingDragged(_ gestureRecognizer: UIPanGestureRecognizer) {

    xFromCenter = gestureRecognizer.translation(in: self).x
    yFromCenter = gestureRecognizer.translation(in: self).y
    switch gestureRecognizer.state {
    //%%% just started swiping
    case .began:
        originalPoint = self.center;
        break;

    //%%% in the middle of a swipe
    case .changed:
        let rotationStrength = min(xFromCenter / ROTATION_STRENGTH, ROTATION_MAX)
        let rotationAngel = .pi/8 * rotationStrength
        let scale = max(1 - fabs(rotationStrength) / SCALE_STRENGTH, SCALE_MAX)
        center = CGPoint(x: originalPoint.x + xFromCenter, y: originalPoint.y + yFromCenter)
        let transforms = CGAffineTransform(rotationAngle: rotationAngel)
        let scaleTransform: CGAffineTransform = transforms.scaledBy(x: scale, y: scale)
        self.transform = scaleTransform
        updateOverlay(xFromCenter)
        break;

    case .ended:
        afterSwipeAction()
        break;

    case .possible:break
    case .cancelled:break
    case .failed:break
    }
}

let panGestureRecognizer = UIPanGestureRecognizer(target: self, action: #selector(self.beingDragged)) addGestureRecognizer(panGestureRecognizer)

Hope this will work . Let me know

thanks

Share:
14,888
Connor
Author by

Connor

Updated on June 08, 2022

Comments

  • Connor
    Connor almost 2 years

    I've followed this very helpful tutorial on how to add tinder-like swiping (http://guti.in/articles/creating-tinder-like-animations/); however, I have one problem- when the picture goes away, I want to replace it with another picture. How/where do I do that?