首页 > 代码库 > (转)iphone上下左右手势判断代码

(转)iphone上下左右手势判断代码

  1.  - (void)viewDidLoad {  
  2.     UISwipeGestureRecognizer *recognizer;   
  3.     recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:selfaction:@selector(handleSwipeFrom:)];   
  4.     [recognizer setDirection:(UISwipeGestureRecognizerDirectionRight)];   
  5.     [[self view] addGestureRecognizer:recognizer];   
  6.     [recognizer release];  
  7.      recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:selfaction:@selector(handleSwipeFrom:)];   
  8.     [recognizer setDirection:(UISwipeGestureRecognizerDirectionUp)];   
  9.     [[self view] addGestureRecognizer:recognizer];   
  10.     [recognizer release];   
  11.       
  12.     recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:selfaction:@selector(handleSwipeFrom:)];   
  13.     [recognizer setDirection:(UISwipeGestureRecognizerDirectionDown)];  
  14.     [[self view] addGestureRecognizer:recognizer];   
  15.     [recognizer release];   
  16.       
  17.     recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:selfaction:@selector(handleSwipeFrom:)];   
  18.     [recognizer setDirection:(UISwipeGestureRecognizerDirectionLeft)];   
  19.     [[self view] addGestureRecognizer:recognizer];   
  20.     [recognizer release];  
  21.   
  22.     [super viewDidLoad];  
  23.  }  
  24.   
  25. -(void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer {   
  26.      NSLog(@"Swipe received.");   
  27.      if (recognizer.direction==UISwipeGestureRecognizerDirectionDown) {   
  28.                 NSLog(@"swipe down");  
  29.     //执行程序  
  30. }  
  31. if (recognizer.direction==UISwipeGestureRecognizerDirectionUp) {   
  32.     NSLog(@"swipe up");  
  33.     //执行程序  
  34. }  
  35. if (recognizer.direction==UISwipeGestureRecognizerDirectionLeft) {   
  36.     NSLog(@"swipe left");  
  37.     //执行程序  
  38. }  
  39. if (recognizer.direction==UISwipeGestureRecognizerDirectionRight) {   
  40.     NSLog(@"swipe right");  
  41.     //执行程序  
  42. }  
  43. }
 

(转)iphone上下左右手势判断代码