8

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

1 回答 1

5

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

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

于 2010-06-20T23:01:40.477 回答