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. }  


其他参考
http://www.cnblogs.com/wujian1360/archive/2011/08/29/2158305.html

http://o0o0o0o.iteye.com/blog/875333

http://blog.sina.com.cn/s/blog_6f40a0e70100p6bt.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值