如何在 Swift 3.0 中创建一个在抬起点击手势时执行的函数

How do I make a function that executes when a tap gesture is lifted in Swift 3.0

有什么方法可以在 iOS 应用程序中设置 tapGestureRecognizer,它可以在点击对象时发送信号, 当点击被释放时,或者设置两个 tapGestureRecognizer,一个处理点击,一个处理释放?

我的 tapGestureRecognizer 初始化如下:

let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(TapInToSubView))
    tapRecognizer.numberOfTapsRequired = 1

    sender.addGestureRecognizer(tapRecognizer)

希望有人能帮忙!

您需要设置一个 UILongPressGestureRecognizer 。设置 minimumPressDuration 然后您可以处理手势状态方法:

(sender.state == UIGestureRecognizerStateEnded)
(sender.state == UIGestureRecognizerStateBegan

等并相应地触发你的行动。

Long-press gestures are continuous. The gesture begins (began) when the number of allowable fingers (numberOfTouchesRequired) have been pressed for the specified period (minimumPressDuration) and the touches do not move beyond the allowable range of movement (allowableMovement). The gesture recognizer transitions to the Change state whenever a finger moves, and it ends (ended) when any of the fingers are lifted.