我想覆盖UITapGestureRecognizer的自定义子类中的touchesBegan。代码如下。我从这里得到它:How to accelerate the identification of a single tap over a double tap?。这是公认的答案,但我得到一个错误:方法不会覆盖任何超类的方法。我已经检查过,这确实似乎是touchesBegan的签名。帮帮我?覆盖touchesBegan:错误 - 方法不会覆盖超类中的任何方法
import UIKit
class UIShortTapGestureRecognizer: UITapGestureRecognizer {
let tapMaxDelay: Double = 0.3
override func touchesBegan(touches: Set<UITouch>, 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
}
}
}
}