iOS 基本手势
-(void)viewDidLoad{ UISwipeGestureRecognizer *recognizerRight; recognizerRight = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipeFrom:)]; [recognizerRight setDirection:(UISwipeGestureRecognizerDirectionRight)]; [[self view] addGestureRecognizer:recognizerRight];
UISwipeGestureRecognizer *recognizerLeft; recognizerLeft = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipeFrom:)]; [recognizerLeft setDirection:(UISwipeGestureRecognizerDirectionLeft)]; [[self view] addGestureRecognizer:recognizerLeft];
UISwipeGestureRecognizer *recognizerUp; recognizerUP = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipeFrom:)]; [recognizerUP setDirection:(UISwipeGestureRecognizerDirectionUp)]; [[self view] addGestureRecognizer:recognizerUP];
UISwipeGestureRecognizer *recognizerDown; recognizerDown = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipeFrom:)]; [recognizerDown setDirection:(UISwipeGestureRecognizerDirectionDown)]; [[self view] addGestureRecognizer:recognizerDown]; } -(void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer{ if(recognizer.direction==UISwipeGestureRecognizerDirectionDown) { NSLog(@"swipe down"); //执行程序 } if(recognizer.direction==UISwipeGestureRecognizerDirectionUp) { NSLog(@"swipe up"); //执行程序 } if(recognizer.direction==UISwipeGestureRecognizerDirectionLeft) { NSLog(@"swipe left"); //执行程序 } if(recognizer.direction==UISwipeGestureRecognizerDirectionRight) { NSLog(@"swipe right"); //执行程序 } }