2

So I am trying to add a swipe gesture to one of the subviews on a screen in my application. I declare the gesture recognizers as follows:

UISwipeGestureRecognizer *swiperR = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(switchStackingMode:)];
    [swiperR setDirection:UISwipeGestureRecognizerDirectionRight];
    [chart addGestureRecognizer:swiperR];

UISwipeGestureRecognizer *swiperL = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(switchStackingMode:)];
    [swiperL setDirection:UISwipeGestureRecognizerDirectionLeft];
    [chart addGestureRecognizer:swiperL];


-(void)switchStackingMode:(UISwipeGestureRecognizer *)sender {
    NSLog(@"inside switchstack from gesture");
    //other stuff
}

When I attempt to interact with the subview on application launch, only the swipe gesture swiperL works. I get no response on a right swipe. I initially tried doing only one gesture recognizer with direction (UISwipeGestureRecognizerDirectionLeft | UISwipeGestureRecognizerDirectionRight) but that didn't work, and based off other stack overflow answers I reverted to two separate recognizers. Still no luck, and this has me puzzled. I feel like I'm missing something..

ascendancy05
  • 227
  • 2
  • 16

2 Answers2

1

This code should works. Are you trying on a device ? swipe gestures are not so easy to do in simulator.

You can do only one gesture with right and left both recognized. This way works with right and left or with up and down, but not with all directions.

iSofTom
  • 1,718
  • 11
  • 15
  • I am trying on a device. After some testing by overlaying a button on top of my 'chart' and adding the gestures to that, the code I have should work. At this point I feel it is worth mentioning I am working with Shinobi Charts, and perhaps the right gesture is being ignored. Going to try to make a workaround – ascendancy05 Jul 19 '12 at 13:47
  • Perhaps I could put a UIButton under the chart and somehow pass the swipe gestures through the chart to the button? – ascendancy05 Jul 19 '12 at 14:03
  • Or add a clear UIView above your chart and add the gestures on it – iSofTom Jul 19 '12 at 14:27
  • I considered doing that but I would lose other interactive elements already implemented on the chart :/ – ascendancy05 Jul 19 '12 at 14:32
0

I answered this here Setting direction for UISwipeGestureRecognizer. I believe the bug is that you can't have your "action" names be the same, i.e. don't have both selectors named "switchStackingMode". Use switchStackingModeRight and switchStackingModeLeft.

Community
  • 1
  • 1
Alex
  • 60
  • 9