Search code examples
iphoneios5uibuttontouchesbegan

TouchesBegan overriding touchUpInside actions


I've implemented a custom UIButton and in order for me to handle LongPress events (without using Gesture Recognizers) I had to use touchesBegan:, touchesEnded: on my class. Problem is that now the regular button events aren't working. I'm wondering what's causing this and how I could avoid it?

The touch based events are working but the previous actions I had for touchUpInside: are no longer functional.

Thanks


Solution

  • don't use touchesBegan: for longpress, use this gesture recognizer!

    UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc]     initWithTarget:self action:@selector(longTap:)];
    [view addGestureRecognizer:longPressGesture];
    [longPressGesture release];
    
    -(void) longTap:(UILongPressGestureRecognizer *)gestureRecognizer{
        NSLog(@"gestureRecognizer= %@",gestureRecognizer);
        if ([gestureRecognizer state] == UIGestureRecognizerStateBegan) {
            NSLog(@"longTap began");
        } 
    }