UIPanGestureRecognizer 没有名为 touchesBegan 的成员
UIPanGestureRecognizer does not have a member named touchesBegan
我正在尝试子类化 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);
}
}
产生这些错误
非常感谢您的帮助。
您不必重写这些函数,您可以像下面这样定义它们。但我不确定为什么会这样。在自定义 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!) {
}
当前接受的答案不太正确,实际上,如果你想继承一个 UIGestureRecognizer,你应该导入 UIGestureRecognizerSubclass.h 头文件,在 https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIGestureRecognizer_Class/index.html 中描述,参见 子类化注释 部分。
与Swift一样,这可以按流程完成:
import UIKit.UIGestureRecognizerSubclass
那么你就可以开始了。
我正在尝试子类化 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);
}
}
产生这些错误
非常感谢您的帮助。
您不必重写这些函数,您可以像下面这样定义它们。但我不确定为什么会这样。在自定义 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!) {
}
当前接受的答案不太正确,实际上,如果你想继承一个 UIGestureRecognizer,你应该导入 UIGestureRecognizerSubclass.h 头文件,在 https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIGestureRecognizer_Class/index.html 中描述,参见 子类化注释 部分。
与Swift一样,这可以按流程完成:
import UIKit.UIGestureRecognizerSubclass
那么你就可以开始了。