UISwipeGestureRecognizer没有可见的接口声明选择器'touchesMoved:withEvent:'

时间:2012-09-24 18:35:11

标签: ios uigesturerecognizer uiswipegesturerecognizer

我收到了一个错误。 “UISwipeGestureRecognizer没有可见的界面声明选择器'touchesMoved:withEvent:'”

我查看了文档,并在UIGestureRecognizer类中找到了touchesMoved:withEvent。我该如何解决这个错误?

@interface MySwipeRecognizer : UISwipeGestureRecognizer

@implementation MySwipeRecognizer

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
 [super touchesMoved:touches withEvent:event];
}
@end

1 个答案:

答案 0 :(得分:1)

除非我误解了这个问题,否则UISwipeGestureRecognizer会为您完成所有触控操作。您的代码看起来像这样:

UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(onSwipe:)];

// set a direction for the swipe
[swipe setDirection:UISwipeGestureRecognizerDirectionLeft];

// self is a view to add the recognizer to:
[self addGestureRecognizer:swipe];

.
.
.

- (void) onSwipe:(id)sender
{
 // a swipe has been recognized!
}

UIGestureRecognizer是一个ABSTRACT类,因此UISwipeGestureRecognizer等具体实现会为您完成所有触摸事件处理。如果您正在尝试创建自己的自定义手势识别器,则需要将UIGestureRecognizer子类化。