Get swipe direction in Cocoa Touch:UISwipeGestureRecognizer只能同时支持一个方向
2012-11-27 13:57
495 查看
I am trying to catch a gesture but it does not work. Here is my code:
and
It always gets a gesture but does not recognize the direction. I also tried
Thanks for any help.
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.
19down voteaccepted | You're not using the UISwipeGestureRecognizercorrectly. Its direction is always going to be what you've set it to (in this case UISwipeGestureRecognizerDirectionRight | UISwipeGestureRecognizerDirectionLeft, or 3). If you want to capture swipes left and right that you can differentiate between, you'll have to set up a separate recognizer for each. Apple does this in their SimpleGestureRecognizers sample. |
19down voteaccepted | You're not using the UISwipeGestureRecognizercorrectly. Its direction is always going to be what you've set it to (in this case UISwipeGestureRecognizerDirectionRight | UISwipeGestureRecognizerDirectionLeft, or 3). If you want to capture swipes left and right that you can differentiate between, you'll have to set up a separate recognizer for each. Apple does this in their SimpleGestureRecognizers sample. |
3down vote | What you have to do is just change the codes for adding gesture recognizer.UISwipeGestureRecognizer *leftRecognizer; leftRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)]; [leftRecognizer setDirection: UISwipeGestureRecognizerDirectionLeft]; [[self view] addGestureRecognizer:leftRecognizer]; [leftRecognizer release]; UISwipeGestureRecognizer *rightRecognizer; rightRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)]; [rightRecognizer setDirection: UISwipeGestureRecognizerDirectionRight]; [[self view] addGestureRecognizer:rightRecognizer]; [rightRecognizer release]; |
19down voteaccepted | You're not using the UISwipeGestureRecognizercorrectly. Its direction is always going to be what you've set it to (in this case UISwipeGestureRecognizerDirectionRight | UISwipeGestureRecognizerDirectionLeft, or 3). If you want to capture swipes left and right that you can differentiate between, you'll have to set up a separate recognizer for each. Apple does this in their SimpleGestureRecognizers sample. |
3down vote | What you have to do is just change the codes for adding gesture recognizer.UISwipeGestureRecognizer *leftRecognizer; leftRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)]; [leftRecognizer setDirection: UISwipeGestureRecognizerDirectionLeft]; [[self view] addGestureRecognizer:leftRecognizer]; [leftRecognizer release]; UISwipeGestureRecognizer *rightRecognizer; rightRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)]; [rightRecognizer setDirection: UISwipeGestureRecognizerDirectionRight]; [[self view] addGestureRecognizer:rightRecognizer]; [rightRecognizer release]; |
相关文章推荐
- UISwipeGestureRecognizerDirection手势上下左右方法
- UISwipeGestureRecognizer 滑动手势方向的判定
- webapi设置一个Action同时支持get和post请求
- javascript中如何让两个radio同时只能选中一个
- 转一份在 51testing 上的讨论——如何测试一个门户网站是否可以支持10万用户同时在线?
- DirectionControlView 一个方向控制自定义View
- 保证同一个账号同时只能在一个设备上登录
- javaweb实现一个账号只能同时被一个人使用(Java实现)
- 使用template扩展已有的DDX_Text函数,使扩展能够同时支持各种数据类型的一个例子
- JSONP原理优缺点(只能GET不支持POST)
- lygrid取消全选同时只能选择一个
- ios学习之UISwipeGestureRecognizer手势识别
- UISwipeGestureRecognizer滑动手势
- django模板中的filter只能支持一个附加参数
- 手势 UISwipeGestureRecognizer 轻扫手势
- 一个项目同时支持两种数据库切换使用的设计
- VC 6.0怎么只能同时打开一个工程?
- Cocoa and Cocoa Touch 一个是用于开发OS X的app 一个是用于开发iPhone的app
- 转一份在 51testing 上的讨论——如何测试一个门户网站是否可以支持10万用户同时在线?
- node如何让一个端口同时支持https与http