Jus*_*ard 2 ios uitapgesturerecognizer swift
我试图覆盖UITapGestureRecognizer的自定义子类中的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
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
问题源于您没有使用Xcode 7的事实。您的语法在Swift 1.2+中,但是您使用的Xcode版本不支持该语法。
如果您将Xcode版本与1.2之前的Swift版本一起使用,则需要如下更改方法签名:
override func touchesBegan(touches: NSSet!, withEvent event: UIEvent?)
Run Code Online (Sandbox Code Playgroud)
或者,升级到Xcode 7。
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?)
Run Code Online (Sandbox Code Playgroud)
从Xcode 6.3开始才可用。
| 归档时间: |
|
| 查看次数: |
1453 次 |
| 最近记录: |