我正在尝试制作一个功能,当用户手指向下时,图像会在转换发生时一直增长到一定大小。我知道如何使图像成长,但不知道如何在用户按下时使其成长。
有谁知道如何让这种情况发生?是否需要LongPressRecognizer?
很抱歉没有代码,但我只想弄清楚如何做到这一点。非常感谢您的帮助!
干杯, 西奥
答案 0 :(得分:2)
你可以这样做:
@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)
}