首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >自制的iOS轻拍手势识别器

自制的iOS轻拍手势识别器
EN

Stack Overflow用户
提问于 2012-09-27 18:24:53
回答 1查看 273关注 0票数 1

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

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

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

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

EN

回答 1

Stack Overflow用户

发布于 2016-03-15 15:34:36

代码语言:javascript
复制
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. 
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12619210

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档