双击手势功能仅在第一次点击后触发,每隔一次它需要 2 次点击

Double tap gesture function is being fired after 1 tap only on first tap, every other instance it requires 2 taps

截至目前,当我 运行 我的程序并点击时,我会在点击后收到 println() 消息。但是,在第一条 println() 消息之后,我必须双击每条后续 println() 消息。

我想要它所以每次我都必须双击(包括第一次)。

在我的视图控制器中,我有以下内容:

@IBOutlet weak var graphview: GraphView! {
    didSet {
        //
        graphview.addGestureRecognizer(UITapGestureRecognizer(target: graphview, action: "doubleTap:"))
    }
}

我在视图中的函数如下:

func doubleTap(gesture: UITapGestureRecognizer)
{
    gesture.numberOfTapsRequired = 2
    println("hit twice")

}

你必须设置

gesture.numberOfTapsRequired = 2

在将手势识别器添加到视图之前,即

@IBOutlet weak var graphview: GraphView! {
    didSet {
        var doubleTap: UITapGestureRecognizer = UITapGestureRecognizer(target: graphview, action: "doubleTap:")
        doubleTap.numberOfTapsRequired = 2
        graphview.addGestureRecognizer(doubleTap)
    }
}

func doubleTap(gesture: UITapGestureRecognizer)
{
    println("hit twice")
}