【发布时间】:2026-01-31 18:40:01
【问题描述】:
我有一个 UIPanGestureRecognizer 设置,里面有几个函数。我希望能够在一个按钮中引用这些功能。
UIPanGestureRecognizer
@IBAction func panCard(_ sender: UIPanGestureRecognizer) {
let card = sender.view!
let point = sender.translation(in: view)
card.center = CGPoint(x: view.center.x + point.x, y: view.center.y + point.y)
func swipeLeft() {
//move off to the left
UIView.animate(withDuration: 0.3, animations: {
card.center = CGPoint(x: card.center.x - 200, y: card.center.y + 75)
card.alpha = 0
})
}
func swipeRight() {
//move off to the right
UIView.animate(withDuration: 0.3, animations: {
card.center = CGPoint(x: card.center.x + 200, y: card.center.y + 75)
card.alpha = 0
})
}
if sender.state == UIGestureRecognizerState.ended {
if card.center.x < 75 {
swipeLeft()
return
} else if card.center.x > (view.frame.width - 75) {
swipeRight()
return
}
resetCard()
}
}
还有按钮
@IBAction func LikeButton(_ sender: UIButton) {
}
如何在按钮内引用两个函数 swipeLeft 和 swipeRight?
【问题讨论】:
标签: swift uibutton uipangesturerecognizer func