I'm writing code to move my two fingers up or down on a view to change some status. The code as below:
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");
}
}
However the only print log I could receive was Swipe received as below shows. I couldn't get the message for swipe up or swipe down, did I miss anything? Thanks
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.
Updated: I have to use two fingers to finish the swipe action.
Try this
UISwipeGestureRecognizer *aSwipeGestureUp = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGesture:)];
[aSwipeGesture setDirection:UISwipeGestureRecognizerDirectionUp];
aSwipeGestureUp.numberOfTouchesRequired = 2;
[self.View addGestureRecognizer:aSwipeGestureUp];
UISwipeGestureRecognizer *aSwipeGestureDown = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGesture:)];
[aSwipeGestureDown setDirection:UISwipeGestureRecognizerDirectionDown];
aSwipeGestureDown.numberOfTouchesRequired = 2;
[self.View addGestureRecognizer:aSwipeGestureDown];