0

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

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

@interface MySwipeRecognizer : UISwipeGestureRecognizer

@implementation MySwipeRecognizer

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

1 回答 1

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。

于 2012-09-24T19:28:29.843 回答