我想编写我自己的点击手势识别器,来检测点击的次数和触摸的次数(我不想使用iOS的点击手势识别器,因为我想稍后以各种其他方式扩展它);
我尝试了以下方法:使用第一个motionBegin触摸次数作为点击的numberOfTouches,递增numberOfTaps,如果在一段时间内没有看到新的点击,则启动点击检测计时器来检测点击手势
问题是,人们很快就会意识到,当进行双触摸点击手势时,iOS要么正确地检测到一个带有双触摸的motionBegin,要么检测到两个快速的单触摸事件。我想一个正确的实现应该尝试检测那些发生在附近的快速单触式事件,但我想知道是否有更好的方法来实现手势识别器。
有人知道iOS点击手势是如何实现的吗?
发布于 2016-03-15 15:34:36
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.
}https://stackoverflow.com/questions/12619210
复制相似问题