0

在我的项目中,我有一个类似于火种卡视图的视图。我的视图运行良好,但我不确定是什么导致它“崩溃”。当我向右滑动时,卡开始抖动并到处跳跃,但是当我向左滑动时,我没有问题并且很流畅。

https://youtu.be/h0r5RuOPe9g -> 这是错误视频

这是我的代码的一些片段。

@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
}
4

0 回答 0