//单指单击
UITapGestureRecognizer *singleFingerOne = [[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(handleSingleFingerEvent:)];
singleFingerOne.numberOfTouchesRequired = 1; //手指数
singleFingerOne.numberOfTapsRequired = 1; //tap次数
singleFingerOne.delegate = self;
//单指双击
UITapGestureRecognizer *singleFingerTwo = [[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(handleSingleFingerEvent:)];
singleFingerTwo.numberOfTouchesRequired = 1;
singleFingerTwo.numberOfTapsRequired = 2;
singleFingerTwo.delegate = self;
//双指单击
UITapGestureRecognizer *doubleFingerOne = [[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(handleDoubleFingerEvent:)];
doubleFingerOne.numberOfTouchesRequired = 2;
doubleFingerOne.numberOfTapsRequired = 1;
doubleFingerOne.delegate = self;
UITapGestureRecognizer *doubleFingerTwo = [[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(handleDoubleFingerEvent:)];
doubleFingerTwo.numberOfTouchesRequired = 2;
doubleFingerTwo.numberOfTapsRequired = 2;
doubleFingerTwo.delegate = self;
//如果不加下面的话,当单指双击时,会先调用单指单击中的处理,再调用单指双击中的处理
[singleFingerOne requireGestureRecognizerToFail:singleFingerTwo];
//同理双指亦是如此
[doubleFingerOne requireGestureRecognizerToFail:doubleFingerTwo];
[self.view addGestureRecognizer:singleFingerOne];
[self.view addGestureRecognizer:singleFingerTwo];
[self.view addGestureRecognizer:doubleFingerOne];
[self.view addGestureRecognizer:doubleFingerTwo];
[singleFingerOne release];
[singleFingerTwo release];
[doubleFingerOne release];
[doubleFingerTwo release];
处理事件的方法,代码:
//处理单指事件
- (void)handleSingleFingerEvent:(UITapGestureRecognizer *)sender
{
if (sender.numberOfTapsRequired == 1) {
//单指单击
NSLog(@"单指单击");
}else if(sender.numberOfTapsRequired == 2){
//单指双击
NSLog(@"单指双击");
}
}
//处理双指事件
- (void)handleDoubleFingerEvent:(UITapGestureRecognizer *)sender
{
if (sender.numberOfTapsRequired == 1) {
//双指单击
NSLog(@"双指单击");
}else if(sender.numberOfTapsRequired == 2){
//双指双击
NSLog(@"双指双击");
}
}
关于UITapGestureRecognizer (给控件添加点击事件)
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- -(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent *)...
- swift3.0 开发过程中,遇到在懒加载控件的时候添加点击事件,事件不能被调用,如图懒加载: 我懒加载一个seg...
- 最近小白项目里遇到一些问题,让小白很抓狂吖!其中一个就是如何通过tag获取控件,实现image数组添加点击事件的问...
- 又一次在半夜写文章,又是一次次纠结不得其果。决定还是写下来吧。 我跟A是在一家以英语培训出名的外企实习时认识的。当...