本文介绍了如何通过双击加速识别单个水龙头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带行的UITableView,我添加了单击手势和双击手势:

I have a UITableView with row where I added single tap gesture and double tap gesture:

let doubleTap = UITapGestureRecognizer(target: self, action: "doubleTap:")
doubleTap.numberOfTapsRequired = 2
doubleTap.numberOfTouchesRequired = 1
tableView.addGestureRecognizer(doubleTap)

let singleTap = UITapGestureRecognizer(target: self, action: "singleTap:")
singleTap.numberOfTapsRequired = 1
singleTap.numberOfTouchesRequired = 1
singleTap.requireGestureRecognizerToFail(doubleTap)
tableView.addGestureRecognizer(singleTap)

有没有办法减少第一次点击和手势识别器实现之间的时间这是一个单击而不是双击。

Is there a way to reduce the time between when the first tap is made and when the gesture recognizer realize that it is a single tap and not a double tap.

我问这个是因为当我点击一下时,新的viewController显得很晚,给人一种感觉该应用程序滞后。

I'm asking this because when I do a single tap, the new viewController appear quite late, giving a feeling that the app lags.

推荐答案

我找到了答案在这个

swift版本:

class UIShortTapGestureRecognizer: UITapGestureRecognizer {
    let tapMaxDelay: Double = 0.3

    override func touchesBegan(touches: NSSet!, withEvent event: UIEvent!) {
        super.touchesBegan(touches, withEvent: event)
        delay(tapMaxDelay) {
            // Enough time has passed and the gesture was not recognized -> It has failed.
            if  self.state != UIGestureRecognizerState.Ended {
                self.state = UIGestureRecognizerState.Failed
            }
        }
    }
}

延迟(延迟:双倍,结束:() - >())

class func delay(delay:Double, closure:()->()) {
        dispatch_after(dispatch_time( DISPATCH_TIME_NOW, Int64(delay * Double(NSEC_PER_SEC))), dispatch_get_main_queue(), closure)
    }

这篇关于如何通过双击加速识别单个水龙头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 11:44