簡體   English   中英

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)

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM