我有UIImageview自己的位置,點擊后(完成tapgesture)我希望該視圖落到地面,直到位置為 0。我嘗試使用 while 回圈制作它,但似乎不起作用。任何解決方案?
var bananaView = UIImageView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
@objc func handleTap(_ sender:UITapGestureRecognizer) {
let centerPosition = bananaView.frame.origin.y
while centerPosition >= 0 {
bananaView.layer.position = CGPoint(x: 0,y : centerPosition - 1)
}
}
uj5u.com熱心網友回復:
您為其設定新位置 (0)。然后將布局更新包裝在影片塊中
@objc func handleTap(_ sender:UITapGestureRecognizer) {
let centerPosition = bananaView.frame.origin.y
Timer.scheduledTimer(withTimeInterval: 0.1, repeats: true) { timer in
if bananaView.frame.origin.y - bananaView.frame.height == 0 {
timer.invalidate()
} else {
bananaView.frame.origin.y -= 1
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/347594.html
