我有一些麻烦来处理iPhone
刷卡,我在界面中创建一个UISwipeGestureRecognizer
VAR:轻扫手势iphone
UISwipeGestureRecognizer *swipeRecognizer;
,并在我的控制器:viewDidLoad
方法
- (void)viewDidLoad
{
[super viewDidLoad];
// Horizontal swipe
swipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self
action:@selector(swipeMethod:)];
swipeRecognizer.direction = UISwipeGestureRecognizerDirectionRight | UISwipeGestureRecognizerDirectionLeft;
[self addGestureRecognizer:swipeRecognizer];
}
而我的方法处理滑动是:
-(void)swipeMethod: (UISwipeGestureRecognizer *) sender
{
NSLog(@"Swipe!");
}
当我运行我的代码和d o刷卡什么都没有?我应该得到:刷卡!
谢谢。
不要将它添加到self,要么使用self.view(假设self是viewcontroller),要么使用子视图将手势识别器置于其上。您可以在放置识别器之前放置一个断点并查看它是否正确添加。看到我的答案左和右滑动检测:http://stackoverflow.com/a/16810160/936957 – 2013-05-29 09:32:21