1.给View添加手势
//view添加两个手势检测方法
self.currentPlayerView.userInteractionEnabled = YES;
UITapGestureRecognizer *singleTapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleSingleTap:)];
singleTapGesture.numberOfTapsRequired =;
singleTapGesture.numberOfTouchesRequired =;
[self.currentPlayerView addGestureRecognizer:singleTapGesture]; UITapGestureRecognizer *doubleTapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleDoubleTap:)];
doubleTapGesture.numberOfTapsRequired =;
doubleTapGesture.numberOfTouchesRequired =;
//只有当doubleTapGesture识别失败的时候(即识别出这不是双击操作),singleTapGesture才能开始识别
[singleTapGesture requireGestureRecognizerToFail:doubleTapGesture];
[self.currentPlayerView addGestureRecognizer:doubleTapGesture];
2.两个手势事件分别 区分单击了 还是双击了
//两个手势分别响应的方法
-(void)handleSingleTap:(UIGestureRecognizer *)sender{
NSLog(@"单击--------------");
} -(void)handleDoubleTap:(UIGestureRecognizer *)sender{
NSLog(@"双击-------------- ");
}
参考文章地址 :https://www.jianshu.com/p/cdcde32cb252