0

In my project I have a view that is like the tinder card view. I had the view working well, but I'm not sure what happened to cause it to "crash". When I swipe right, the card starts jittering and jumping all over the place, but when I swipe left, I have no problems and it is smooth.

https://youtu.be/h0r5RuOPe9g -> this is a video of the error

Here are some snippets of my code.

@IBAction func panCard(_ sender: UIPanGestureRecognizer) {

    let card = sender.view!

    let point = sender.translation(in: view)

    let xFromCenter = card.center.x - view.center.x

    card.center = CGPoint(x: view.center.x + point.x, y: view.center.y + point.y)

    let scale = min(100/abs(xFromCenter),1)

    card.transform = CGAffineTransform(rotationAngle: xFromCenter/divisor).scaledBy(x: scale, y: scale) //Rotating the card and scaling the card as it swipes to the left or right.

    if xFromCenter > 0{
        //Sets image to thumbs up if the card is moved right

        thumbImage.image = #imageLiteral(resourceName: "thisAccept") // This seems to be the section of the code that is causing the issue. the "thisAccept" image is .png and is in my asset file.

        thumbImage.contentMode = .scaleAspectFit
        thumbImage.tintColor = UIColor.green
    }else{
        //Sets image to thumbs down if the card is moved left
        thumbImage.image = #imageLiteral(resourceName: "Decline")
        thumbImage.contentMode = .scaleAspectFit
        thumbImage.tintColor = UIColor.red
    }

   thumbImage.alpha = abs(xFromCenter) / (view.center.x) // Fading the image as it swipes left or right
}
Cesa Salaam
  • 77
  • 11
  • "to cuz it crash" It crashes? Do you have an error message in console explaining why it would crash? – Larme Jan 23 '18 at 16:04
  • My apologies for the typos. That just it, there is no error message. As I swipe right on the card, the card starts jumping all over the place. I was able to pinpoint the error down to " thumbImage.image = #imageLiteral(resourceName: "thisAccept")" but I'm not sure what exactly is wrong because when I swipe left I have no problem. – Cesa Salaam Jan 23 '18 at 16:09
  • I uploaded a video to show the error – Cesa Salaam Jan 23 '18 at 16:15
  • use icrousal Or kollada – Abhishek Thapliyal Jan 23 '18 at 16:16
  • This may help you - [Tinder-Like Swipe Animation for iOS](https://stackoverflow.com/questions/22852934/tinder-like-swipe-animation-for-ios) or [Tinder like pan iOS](https://stackoverflow.com/questions/21993020/tinder-like-pan-ios) – Krunal Jan 23 '18 at 16:44
  • check this out https://www.github.com/nickypatson/TinderSwipeView – nickypatson May 29 '18 at 06:59

0 Answers0