我正在编写代码以在视图上向上或向下移动我的两根手指以更改某些状态。代码如下:
UISwipeGestureRecognizer *aSwipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGesture:)];
[aSwipeGesture setDirection:UISwipeGestureRecognizerDirectionUp | UISwipeGestureRecognizerDirectionDown];
aSwipeGesture.numberOfTouchesRequired = 2;
[self.View addGestureRecognizer:aSwipeGesture];
- (void)swipeGesture:(UISwipeGestureRecognizer *)sender {
NSLog(@"Swipe received.");
if (sender.direction==UISwipeGestureRecognizerDirectionUp) {
NSLog(@"swipe up");
} else if (sender.direction==UISwipeGestureRecognizerDirectionDown) {
NSLog(@"swipe down");
}
}
然而,我能收到的唯一打印日志是 Swipe 收到,如下所示。我无法收到向上或向下滑动的消息,我错过了什么吗?谢谢
ViewController.m:228 Swipe received.
ViewController.m:228 Swipe received.
ViewController.m:228 Swipe received.
ViewController.m:228 Swipe received.
ViewController.m:228 Swipe received.
ViewController.m:228 Swipe received.
更新:我必须用两根手指来完成滑动动作。