1

我想编写自己的点击手势识别器,以检测点击次数和触摸次数(我不想使用 iOS 点击手势识别器,因为我想稍后以各种其他方式扩展它);

我尝试了以下方法:使用第一次motionBegin触摸作为numberOfTouches点击,增加numberOfTaps,并启动点击检测计时器以检测点击手势,如果一段时间内没有看到新的点击

问题是人们很快就会意识到,在执行双击手势时,iOS 要么正确地检测到一个motionBegin双击事件,要么检测到两个快速的一键事件。我想一个正确的实现应该尝试检测那些紧密发生的快速一键式事件,但我想知道是否有更好的方法来实现手势识别器。

有人知道 iOS 点击手势是如何实现的吗?

4

1 回答 1

0
1. Add UIGestureRecognizerDelegate in your .h file. like
@interface finalScreenViewController : UIViewController <UIGestureRecognizerDelegate>
{
// do your stuff
}


2. Create a view in your viewDidLoad method (or any other method) you wanna to add the gesture in your .m file
ex 

UIView * myView=[[UIView alloc]init];
myView.frame=CGRectMake(0,0.self.view.frame.size.width,self.view.frame.size.height);
[self.view addSubView: myView];



UITapGestureRecognizer *letterTapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapMethod:)];
        letterTapRecognizer.numberOfTapsRequired = 1;
        [myView addGestureRecognizer:letterTapRecognizer];



3. you can get view by

- (void) tapMethod:(UITapGestureRecognizer*)sender {
     UIView *view = sender.view; 
     NSLog(@"%d", view.tag);//By tag, you can find out where you had tapped. 
}
于 2016-03-15T07:34:36.437 回答