gpt4 book ai didi

iphone - 此时如何识别oneTap/doubleTap?

转载 作者:行者123 更新时间:2023-12-03 18:29:09 25 4
gpt4 key购买 nike

我知道使用 Apple API 过滤 oneTap/doubleTap。代码如下。

UITapGestureRecognizer *doubleTapGestureRecognizer = [[UITapGestureRecognizer alloc]
initWithTarget:self action:@selector(handleDoubleTap:)];
doubleTapGestureRecognizer.numberOfTapsRequired = 2;


[self addGestureRecognizer:doubleTapGestureRecognizer];


UITapGestureRecognizer *singleTapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
singleTapGestureRecognizer.numberOfTapsRequired = 1;

**[singleTapGestureRecognizer requireGestureRecognizerToFail: doubleTapGestureRecognizer];**

[self addGestureRecognizer:singleTapGestureRecognizer];

但是 oneTap/doubleTap checkDelayTime 感觉很长(大约 0.5 秒?)。一般来说App用户的 react 是非常快的。虽然 0.5 秒通常是很短的时间。但在移动设备环境中是很长时间的,因为用户的 react 非常重要。

说到重点,YouTubeApp enter image description here有一个非常完美的关于瞬间过滤的算法oneTap/doubleTap。 oneTap-doubleTap checkDelay 是 VeryVeryShort 完美优化。

oneTap(显示/隐藏控制栏)

doubleTap(完整/默认 videoScreenSize)

像YoutubeApp一样如何实现?关于 oneTap-doubleTap 过滤 不使用 requireGestureRecognizerToFail 选择器。关于非常短的延迟oneTap-doubleTap的区分。

我认为 YoutubeApp 没有使用 requireGestureRecognizer 选择器。

最佳答案

最简单的方法是子类化 UITapGestureRecognizer 而不是通用的 UIGestureRecognizer。

像这样:

#import <UIKit/UIGestureRecognizerSubclass.h>

#define UISHORT_TAP_MAX_DELAY 0.2
@interface UIShortTapGestureRecognizer : UITapGestureRecognizer

@end

并简单地实现:

@implementation UIShortTapGestureRecognizer

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesBegan:touches withEvent:event];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(UISHORT_TAP_MAX_DELAY * NSEC_PER_SEC)), dispatch_get_main_queue(), ^
{
// Enough time has passed and the gesture was not recognized -> It has failed.
if (self.state != UIGestureRecognizerStateRecognized)
{
self.state = UIGestureRecognizerStateFailed;
}
});
}
@end

关于iphone - 此时如何识别oneTap/doubleTap?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8051627/

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