我正在尝试继承UIPanGestureRecognizer,我想我可能会做一些愚蠢的事情。我试图覆盖UIPanGestureRecognizer从UIGestureRecognizer继承的方法时遇到错误。
我有这段代码
class VPGesture: UIPanGestureRecognizer {
override func touchesBegan(touches: NSSet!, withEvent event: UIEvent!) {
super.touchesBegan(touches, withEvent: event)
}
override func touchesMoved(touches: NSSet!, withEvent event: UIEvent!) {
super.touchesMoved(touches, withEvent: event);
}
override func touchesEnded(touches: NSSet!, withEvent event: UIEvent!) {
super.touchesEnded(touches, withEvent: event);
}
override func touchesCancelled(touches: NSSet!, withEvent event: UIEvent!) {
super.touchesCancelled(touches, withEvent: event);
}
}
产生这些错误
非常感谢你的帮助。
答案 0 :(得分:16)
当前接受的答案并不完全正确,实际上,如果要创建UIGestureRecognizer的子类,则应导入 UIGestureRecognizerSubclass.h 头文件,该文件在{{ 3}},请参阅子类注释部分。
与Swift一样,这可以作为流程来完成:
import UIKit.UIGestureRecognizerSubclass
然后你准备好了。
答案 1 :(得分:0)
您不必覆盖这些功能,您可以像下面一样定义它们。但我不确定为什么会这样。在自定义UIView
中,必须覆盖这些函数。
func touchesBegan(touches: NSSet!, withEvent event: UIEvent!) {
println("here")
}
func touchesMoved(touches: NSSet!, withEvent event: UIEvent!) {
}
func touchesEnded(touches: NSSet!, withEvent event: UIEvent!) {
}
func touchesCancelled(touches: NSSet!, withEvent event: UIEvent!) {
}