Gesture Recognizer on SChartAnnotation


#1

Has anyone had any success with placing a gesture recognizer on an annotation in a line chart? 

 

I would like to add gestureRecognizers to a band annotation, and so far I haven’t had much success. The recognizers all seem to be consumed by the chart. 

 

Below is a snippet of my code where I’m attempting to add the recognizer to the annotation. 

 

 

    SChartAnnotation *band = [SChartAnnotation verticalBandAtPosition:position andMaxX:maxX withXAxis:self.chart.xAxis andYAxis:self.chart.yAxis withColor:[UIColor grayColor]];

    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(contractBandTapped:)];

    [band addGestureRecognizer:tap];

    UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(contractBandLongTap:)];

    [band addGestureRecognizer:longPress];

    [self.chart bringSubviewToFront:band];

    [self.chart addAnnotation:band];

    [band updateViewWithCanvas:self.chart.canvas];

 


#2

Hi Dave, 
  
I suspect that the problem you’re encountering here is that the chart is ‘eating’ the gestures before they can reach your annotation. 
You can disable gestures on the chart using: 
chart.gesturePanType = SChartGesturePanTypeNone; 
  
You should also avoid setting crosshairEnabled to true on any of your chart series as this will also use long press gestures. 
  
I hope this helps!
  
Cheers, 

Simon  :smile: