iPad 手势识别器 - 延迟响应

发布于 2024-09-06 19:57:27 字数 1630 浏览 3 评论 0原文

在我的应用程序中,我添加了 3.2 SDK 中提供的新手势识别器。一切似乎都工作正常,屏幕上的响应时间非常快。但由于某种原因,当我将 requireGestureRecognizerToFail 添加到某些手势时,触发手势时会出现非常明显的延迟。下面是我用来创建手势识别器的代码片段。有谁知道为什么会出现延迟以及如何解决它?我使用 requireGestureRecognizerToFail 来防止用户执行 DoubleTap 时触发 SingleTap 手势。

 - (void)createGestureRecognizers {

 //Single Finger Double-Tap
 UITapGestureRecognizer *singleFingerDTap = [[UITapGestureRecognizer alloc]
            initWithTarget:self action:@selector(handleSingleDoubleTap:)];
    singleFingerDTap.numberOfTapsRequired = 2;
    [super addGestureRecognizer:singleFingerDTap];

 //Single Finger Tap
 UITapGestureRecognizer *singleFingerTap = [[UITapGestureRecognizer alloc]
              initWithTarget:self action:@selector(handleSingleTap:)];
    singleFingerTap.numberOfTapsRequired = 1;
 [singleFingerTap  requireGestureRecognizerToFail:singleFingerDTap];
 [self addGestureRecognizer:singleFingerTap];

 //Two Finger Pan
 UIPanGestureRecognizer *panGesture2 = [[UIPanGestureRecognizer alloc]
            initWithTarget:self action:@selector(handlePanGesture2:)];
    panGesture2.maximumNumberOfTouches = 2;
 [super addGestureRecognizer:panGesture2];

 //Single Finger Pan
 UIPanGestureRecognizer *panGesture1 = [[UIPanGestureRecognizer alloc]
             initWithTarget:self action:@selector(handlePanGesture1:)];
    panGesture1.maximumNumberOfTouches = 1;
 [panGesture1 requireGestureRecognizerToFail:panGesture2];
 [super addGestureRecognizer:panGesture1];

 [singleFingerDTap release];
 [singleFingerTap release];
    [panGesture1 release];
 [panGesture2 release];
}

In my app I have added the new Gesture Recognizers that are available in the 3.2 SDK. Everything appears to be working correctly and the response time on the screen been very fast. But for some reason when I add requireGestureRecognizerToFail to some of my gestures, there is a very visible delay when the gesture is triggered. Below is a snippet of the code that I use to create the Gesture Recognizers. Does anyone know why there is a delay and how I can fix it? I'm using requireGestureRecognizerToFail to prevent the SingleTap gesture from triggering when the user performs a DoubleTap.

 - (void)createGestureRecognizers {

 //Single Finger Double-Tap
 UITapGestureRecognizer *singleFingerDTap = [[UITapGestureRecognizer alloc]
            initWithTarget:self action:@selector(handleSingleDoubleTap:)];
    singleFingerDTap.numberOfTapsRequired = 2;
    [super addGestureRecognizer:singleFingerDTap];

 //Single Finger Tap
 UITapGestureRecognizer *singleFingerTap = [[UITapGestureRecognizer alloc]
              initWithTarget:self action:@selector(handleSingleTap:)];
    singleFingerTap.numberOfTapsRequired = 1;
 [singleFingerTap  requireGestureRecognizerToFail:singleFingerDTap];
 [self addGestureRecognizer:singleFingerTap];

 //Two Finger Pan
 UIPanGestureRecognizer *panGesture2 = [[UIPanGestureRecognizer alloc]
            initWithTarget:self action:@selector(handlePanGesture2:)];
    panGesture2.maximumNumberOfTouches = 2;
 [super addGestureRecognizer:panGesture2];

 //Single Finger Pan
 UIPanGestureRecognizer *panGesture1 = [[UIPanGestureRecognizer alloc]
             initWithTarget:self action:@selector(handlePanGesture1:)];
    panGesture1.maximumNumberOfTouches = 1;
 [panGesture1 requireGestureRecognizerToFail:panGesture2];
 [super addGestureRecognizer:panGesture1];

 [singleFingerDTap release];
 [singleFingerTap release];
    [panGesture1 release];
 [panGesture2 release];
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟─花易冷 2024-09-13 19:57:27

如果您想区分单击和双击,则必须等待足够长的时间才能确定没有第二次点击,然后才能将其称为单击。另一种方法是设计所有单击操作,以便在检测到双击时可以异步取消或恢复这些操作。

例如,如果您有单击更改页面和双击缩放的功能,那么您必须在单击时为页面更改设置动画,然后在检测到第二次点击时反转动画并缩放。到那时,处理单击的视图可能已经移动。在大多数情况下,这会带来更多的麻烦和混乱,而不是值得的。

If you want to distinguish between a single and double tap, you must wait long enough to figure out that no second tap is coming before you can call it a single tap. The alternative would be to design all your single tap actions in such a way that they can asynchronously be canceled or reverted when a double tap is detected.

For example, if you have a single tap change pages and a double tap zoom, then you would have to animate a page changing on single tap, then reverse the animation and zoom instead when a second tap is detected. By then the view that handled the single tap may have moved. In most cases, that is more trouble and confusion then it is worth.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文