在 UIScrollView 中允许单击手势识别器和双击 [英] Allow both single tap gesture recognizer and double tap in UIScrollView

查看:69
本文介绍了在 UIScrollView 中允许单击手势识别器和双击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我在 UIScrollView 中有一个 UIImageView,我需要同时捕获:- 单击手势- 双击手势用于 UIImageView

So I have an UIImageView inside of a UIScrollView, I need to capture both: - single tap gesture - double tap gesture for the UIImageView

双击手势应该作为缩放操作发送到 UIScrollView单击手势由我自己创建的 UITapGestureRecognizer 捕获.双击手势的优先级高于单击(当有双击时,放大滚动视图,否则执行单击)

The double tap gesture is supposed to be sent to the UIScrollView as an action of zooming The single tap gesture is captured by a UITapGestureRecognizer that I created myself. The double tap gesture has higher priority than the single tap (when there is a double tap, zoom in the scrollview, else perform the single tap)

到目前为止,如果我将单击手势识别器添加到滚动视图中,单击会立即被识别并且无法识别双击.

So far if I add the single tap gesture recognizer to the scrollview, the single tap is immediately recognized and no double tap can be recognized.

如果我将单击手势识别器添加到 imageview,它永远不会收到任何动作,但双击有效

If I add the single tap gesture recognizer to the imageview, it never receives any action, but double tap works

感谢任何建议,谢谢..

Any suggestion is appreciated, thanks..

推荐答案

试试这个代码,

目标 - C

 UITapGestureRecognizer *singletap = [[UITapGestureRecognizer alloc]
                                                     initWithTarget:self
                                                     action:@selector(singleTap:)];
    singletap.numberOfTapsRequired = 1;
    singletap.numberOfTouchesRequired = 1;

[scrollView addGestureRecognizer:singletap];


UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc]
                                                 initWithTarget:self
                                                 action:@selector(doubleTap:)];
doubleTap.numberOfTapsRequired =2 ;
doubleTap.numberOfTouchesRequired = 1;

[scrollView addGestureRecognizer:doubleTap];



[singleTap requireGestureRecognizerToFail:doubleTap];

Swift 3.0

var singletap = UITapGestureRecognizer(target: self, action: #selector(self.singleTap))
singletap.numberOfTapsRequired = 1
singletap.numberOfTouchesRequired = 1
scrollView.addGestureRecognizer(singletap)
var doubleTap = UITapGestureRecognizer(target: self, action: #selector(self.doubleTap))
doubleTap.numberOfTapsRequired = 2
doubleTap.numberOfTouchesRequired = 1
scrollView.addGestureRecognizer(doubleTap)
singleTap.require(toFail: doubleTap)

这篇关于在 UIScrollView 中允许单击手势识别器和双击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆