I am trying to catch a gesture but it does not work. Here is my code:
UISwipeGestureRecognizer *recognizer;
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];
[recognizer setDirection:(UISwipeGestureRecognizerDirectionRight | UISwipeGestureRecognizerDirectionLeft)];
[[self view] addGestureRecognizer:recognizer];
[recognizer release];
and
-(void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer {
NSLog(@"get gesture");
if (recognizer.direction == UISwipeGestureRecognizerDirectionRight) {
NSLog(@"get gesture right");
}
if (recognizer.direction == UISwipeGestureRecognizerDirectionLeft) {
NSLog(@"get gesture Left");
}
}
It always gets a gesture but does not recognize the direction. I also tried if(recognizer.direction){NSLog(@"get gesture");}
and it also worked, so I do not understand where I made the mistake.
Thanks for any help.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…