UILongPressGestureRecognizer- 如何在按住的同时增加大小

UILongPressGestureRecognizer- How increase size while holding down

我正在尝试制作一个功能,当用户按住手指时,图像会在发生过渡时变大,直到达到一定大小。我知道如何使图像变大,但不知道如何使其仅在用户按住时才变大。

有谁知道如何做到这一点?是否需要 LongPressRecognizer?

抱歉没有代码,但我只是想弄清楚如何做到这一点。非常感谢您的提前帮助!

干杯, 西奥

你可以这样做:

@IBOutlet weak var myImageView: UIImageView!

var startAnimation = false
func handleTap(gestureRecognizer:UIGestureRecognizer) {

        startAnimation = true
        UIView.animate(withDuration: 0.5, animations: {
            self.myImageView.frame = CGRect(x: 0, y: 0, width: 100, height: 100)
            self.view.layoutIfNeeded()
        }) { (finished) in
            self.startAnimation = false
        }
}

override func viewDidLoad() {
    super.viewDidLoad()

    let gesture = UILongPressGestureRecognizer(target: self, action: #selector(handleTap(gestureRecognizer:)))

    myImageView.isUserInteractionEnabled = true
    myImageView.addGestureRecognizer(gesture)

}