在 Objective-C 中实现 singleTap 和 doubleTap
Posted
技术标签:
【中文标题】在 Objective-C 中实现 singleTap 和 doubleTap【英文标题】:Implement singleTap and doubleTap in Objective-C 【发布时间】:2013-03-22 01:48:45 【问题描述】:我将 singTap 和 doubleTap 添加到如下代码所示的视图中:
-(void)awakeFromNib
[self setUserInteractionEnabled:YES];
//
UITapGestureRecognizer *doubleTapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleTapGesture:)];
doubleTapGesture.numberOfTapsRequired = 2;
[self addGestureRecognizer:doubleTapGesture];
UITapGestureRecognizer *singleTapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTapGesture:)];
singleTapGesture.numberOfTapsRequired = 1;
[self addGestureRecognizer:singleTapGesture];
-(void)handleSingleTapGesture:(UITapGestureRecognizer *)singleTapGesture
[[self delegate] singleTapOnView];
-(void)handleDoubleTapGesture:(UITapGestureRecognizer *)doubleTapGesture
[[self delegate] doubleTapOnView];
当 doubleTap 时,singleTap 也会触发。 doubleTap时如何禁用singleTap?谢谢!
【问题讨论】:
【参考方案1】:告诉单击识别器它需要双击识别器在触发之前失败:
[singleTapGesture requireGestureRecognizerToFail:doubleTapGesture];
(这实际上是UIGestureRecognizer docs for this method中的规范示例。)
【讨论】:
以上是关于在 Objective-C 中实现 singleTap 和 doubleTap的主要内容,如果未能解决你的问题,请参考以下文章
如何在 Objective-C 和 Swift 中实现“didSelectButtonInCellAtIndexPath:”?
如何在objective-c的pickerView中实现多次转换
在 Objective-C 中实现这种滚动 UI 的最佳方式是啥?