2

I'd like to support pre 3.2 and this is the only symbol that doesn't want to cooperate, anyone know of some touchesmoved code or something i can use in lieu of the UILongPressGestureRecognizer?

Thanks,

Nick

nickthedude
  • 4,925
  • 10
  • 36
  • 51

1 Answers1

1

As you know, you should use touchesBegan, Moved, Ended, and Canceled functions for pre 3.2 iOS. I think implementing only touchesMoved is bad because if the user presses and doesn't move at all until releasing, then touchesMoved won't get called ever.

Instead, I used NSTimer to acheive a long press touch event. This might not be an optimal solution, but it worked well for my app. Here's a snippet of code.

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    isAvailable = NO;
    timer = [NSTimer scheduledTimerWithTimeInterval:DURATION target:self selector:@selector(didPassTime:) userInfo:nil repeats:NO];
}

- (void)didPassTime:(id)sender{
    isAvailable = YES;
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
    if(isAvailable == YES){
        // still pressing after 0.5 seconds 
    }
    else{
        // still pressing before 0.5 seconds
    }
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
    if(isAvailable == YES){
        // releasing a finger after 0.5 seconds
    }
    else {
        // releasing a finger before 0.5 seconds
            [timer invalidate];
            timer = nil;
    }



}
pnmn
  • 1,127
  • 1
  • 14
  • 22