gpt4 book ai didi

ios - 在 UIScrollView 中允许单击手势识别器和双击

转载 作者:行者123 更新时间:2023-12-01 17:25:13 27 4
gpt4 key购买 nike

所以我在 UIScrollView 中有一个 UIImageView,我需要捕获两者:- 单击手势- 双击手势对于 UIImageView

双击手势应该作为缩放 Action 发送到 UIScrollView单击手势由我自己创建的 UITapGestureRecognizer 捕获。双击手势比单击具有更高的优先级(当有双击时,放大 ScrollView ,否则执行单击)

到目前为止,如果我将单击手势识别器添加到 ScrollView ,单击会立即被识别,而不会识别双击。

如果我将单击手势识别器添加到 imageview,它永远不会收到任何 Action ,但双击可以工作

感谢任何建议,谢谢..

最佳答案

试试这段代码,

目标 - 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)

关于ios - 在 UIScrollView 中允许单击手势识别器和双击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29298567/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com