我想覆蓋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
}
}
}
}