UISwipeGestureRecognizer

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

最佳答案

除非我对这个问题有误解,否则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子类化。

关于ios - UISwipeGestureRecognizer没有可见的接口(interface)声明选择器'touchesMoved:withEvent:',我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12570821/

10-14 23:24
查看更多