gpt4 book ai didi

ios - 在 Objective-C 中实现 singleTap 和 doubleTap

转载 作者:可可西里 更新时间:2023-11-01 03:28:51 24 4
gpt4 key购买 nike

我将 singTap 和 doubleTap 添加到如下代码的 View 中:

-(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];
}

当双击时,singleTap 也会触发。如何在双击时禁用 singleTap?谢谢!

最佳答案

告诉单击识别器它需要双击识别器在触发之前失败:

[singleTapGesture requireGestureRecognizerToFail:doubleTapGesture];

(这实际上是 UIGestureRecognizer docs for this method 中的典型示例。)

关于ios - 在 Objective-C 中实现 singleTap 和 doubleTap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15561350/

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