在我的应用程序中,我添加了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];
}
答案 0 :(得分:6)
如果你想区分单击和双击,你必须等待足够长的时间才能确定没有第二次敲击即可,然后你可以单击它。另一种方法是设计所有单击操作,以便在检测到双击时异步取消或恢复它们。
例如,如果您只有一个点击更改页面和双击缩放,则必须在单击时更改页面动画,然后在检测到第二次点击时反转动画并缩放。到那时,处理单击的视图可能已经移动。在大多数情况下,这是更麻烦和困惑,那么它是值得的。