本文介绍了touchesEnded:withEvent:如何解决延迟,然后再触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iPhone OS上,除非有阻力,否则-touchesEnded:withEvent:在您离开手指时会快速触发.如果-touchesMoved:withEvent:已触发,那么在您获得touchesEnded:withEvent:之前大约有0.6秒的延迟.

On iPhone OS, -touchesEnded:withEvent: fires quickly when you left a finger, unless there was a drag. If -touchesMoved:withEvent: has fired, then there is about a 0.6 second delay before you get touchesEnded:withEvent:.

我在一个新项目中对此进行了验证,没有scrollView,没有多点触摸.

I verified this in a new project, no scrollView, no multi-touch.

我希望用户拖动一个对象,然后只要抬起手指就可以触发方法. 0.6秒的延迟是不可接受的.

I want the user to drag an object around, and then have a method fire as soon as he lifts a finger. The 0.6 second delay is unacceptable.

有什么想法要解决吗?

我在测试项目中编写的唯一代码是:

The only code I have written in the test project is this:

   @implementation MyView

// startTime is an ivar
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    startTime = [NSDate timeIntervalSinceReferenceDate];
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    NSLog(@"%f", [NSDate timeIntervalSinceReferenceDate] - startTime);
}

推荐答案

发现了问题:Magic Trackpad.当您运行模拟器时,Magic Trackpad会在确定您结束触摸之前添加一个延迟.

Found the problem: Magic Trackpad. When you run the Simulator, Magic Trackpad adds a delay before it decides that you have ended a touch.

这篇关于touchesEnded:withEvent:如何解决延迟,然后再触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 00:07