简体   繁体   English

UILongPressGestureRecognizer-如何在按住的同时增大尺寸

[英]UILongPressGestureRecognizer- How increase size while holding down

I am trying to make a feature where while the user is holding their finger down, an image grows until it is a certain size when a transition occurs. 我正在尝试创建一个功能,在该功能下,用户按住手指时,图像会一直增长到发生过渡时达到一定大小为止。 I know how to make the image grow, but do not know how to make it grow ONLY WHEN the user is holding down. 我知道如何使图像变大,但是不知道仅当用户按住时才使图像变大。

Does anyone know how to make this occur? 有谁知道如何做到这一点? Does one need the LongPressRecognizer? 是否需要LongPressRecognizer?

Sorry for no code, but I am just trying to figure out how to do this. 抱歉,没有代码,但是我只是想弄清楚该怎么做。 Thanks so much for your help in advance! 非常感谢您的提前帮助!

Cheers, Theo 干杯,西奥

You could do it like this: 您可以这样做:

@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)

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM