![](/img/trans.png)
[英]How to increase the size of the tableview cell gradually upon holding it
[英]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)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.