3

I need to do some actions when the user starts touching the screen, moves a finger and then ends a touch. Touch began works fine, move as well, but touch end runs with a delay between 0.5-1 sec. Below there's a code:

-(id) init {    
    if (self = [super init]) {
        //Adding a listener for catching touch events and get call back to selector method 
        [self addGestureListener:@selector(gestureCallback:)];

        CCScene *scene = [CCScene node];

        [scene addChild: self];

        [[CCDirector sharedDirector] runWithScene:scene];
    }
    return self;
} 

- (UIPanGestureRecognizer *)addGestureListener:(SEL)selector {
    UIPanGestureRecognizer *recognizer = [[[UIPanGestureRecognizer alloc] initWithTarget:self action:selector] autorelease];
    [[[CCDirector sharedDirector] openGLView] addGestureRecognizer:recognizer];
    return recognizer;
}

-(void) gestureCallback:(UIPanGestureRecognizer *) recognizer {

    if (recognizer.state == UIGestureRecognizerStateBegan) {
        NSLog(@"start");
    } else if (recognizer.state == UIGestureRecognizerStateChanged) {
        NSLog(@"moved");
    } else if (recognizer.state == UIGestureRecognizerStateEnded) {
        NSLog(@"ended");
    }
}

In the log (last 2 lines) I see this:

2012-10-15 11:29:03.609 App[6169:c07] moved
2012-10-15 11:29:04.267 App[6169:c07] ended

Any ideas?

4

2 回答 2

1

查看 GestureRecognizer 的delaysTouchesEnded 属性。来自 Apple 的文档:

当此属性的值为 YES(默认值)并且接收器正在分析触摸事件时,窗口会暂停将 UITouchPhaseEnded 阶段的触摸对象传递到附加视图。如果手势识别器随后识别出它的手势,则取消这些触摸对象(通过 touchesCancelled:withEvent: 消息)。如果手势识别器无法识别其手势,则窗口在调用视图的 touchesEnded:withEvent: 方法时传递这些对象。将此属性设置为 NO 以在手势识别器分析相同的触摸时将 UITouchPhaseEnded 中的触摸对象传递到视图。

于 2013-10-31T22:04:56.007 回答
0

我只是在模拟器上得到这个延迟。当我使用物理设备时,我没有看到相同的延迟。

于 2019-02-13T17:27:18.040 回答