The size of the image should depend on the time the button is clamped. My size changes at the beginning of the clamping and that's it, but it’s necessary that it be changed relative to the clamping time.

var startTime = Date() @IBOutlet weak var button: UIButton! @IBOutlet weak var heartImageView: UIImageView! override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. let longPresss = UILongPressGestureRecognizer(target: self, action: #selector(longPress)) longPresss.delegate = self button.addGestureRecognizer(longPresss) } func longPress(gesture: UILongPressGestureRecognizer) { print(heartImageView.frame.size) if gesture.state == .began { let duration = Date().timeIntervalSince(startTime) print("duration \(Int(duration)) seconds") UIView.animate(withDuration: 0.5, animations: { if Int(duration) < 3 { self.heartImageView.transform = CGAffineTransform(scaleX: 1.35, y: 1.35) } else { self.heartImageView.alpha = 0 } }, completion: nil) } else if gesture.state == .ended { let duration = Date().timeIntervalSince(startTime) print("duration was \(Int(duration)) seconds") } } 
  • And the question is what? - Max Mikheyenko
  • My image size changes at the beginning of the clamping (in the first 2 seconds), and I need the image size to change in proportion to the clamping time - Waver

1 answer 1

Based on Apple documentation : Long-press gestures are continuous. The gesture begins (when it comes to the number of allowable fingers), it can be used to make it. There are lifts.

The default value of allowableMovement is 10, try to increase it, when you press it, the finger moves beyond 10 point, and also see if gesture.state == .cancelled arrives