Note that there are some explanatory texts on larger screens.

plurals
  1. POCombining swipe down and long press
    primarykey
    data
    text
    <p>I'm trying to implement in my ViewController( which has a tableView) two gesture recognisers that have to work one after another. The first one is a swipe down gesture and the second a long press gesture. </p> <p>Here's my code modified with @sergio suggestions </p> <pre><code> - (void)viewDidLoad { [super viewDidLoad]; swipeDown = [[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeDownAction)] autorelease]; longPress = [[[CustomLongPress alloc]initWithTarget:self action:@selector(longPressAction)] autorelease]; longPress.minimumPressDuration = 2; swipeDown.numberOfTouchesRequired = 1; swipeDown.direction = UISwipeGestureRecognizerDirectionDown; swipeDown.delegate = self ; longPress.delegate = self ; [myTableView addGestureRecognizer:swipeDown]; [myTableView addGestureRecognizer:longPress]; } -(void)swipeDownAction { _methodHasBeenCalled = YES; // bool @property declared in .h NSLog(@"Swipe down detected"); } -(void)longPressAction { NSLog(@"long press detected"); } - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { return YES; } </code></pre> <p>And my UILongPressGestureRecognizer subclass:</p> <pre><code>#import "CustomLongPress.h" #import "ViewController.h" @interface CustomLongPress() { ViewController *vc; } @end @implementation CustomLongPress -(id)initWithTarget:(id)target action:(SEL)action controller:(ViewController *)viewCon { self = [super initWithTarget:target action:action]; if (self) { vc = viewCon; } return self; } -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { NSLog(vc.methodHasBeenCalled ? @"Yes" : @"No"); if (vc.methodHasBeenCalled) { [super touchesBegan:touches withEvent:event]; } } </code></pre> <p>Unfortunately, I still get only the log from swipeDown but no log when it comes to longPress</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload