Detect single tap on chart (iOS)


#1

Hey guys,

I’d like to fade in additional control elements once the user tapped on the chart, I just can’t recognise the single tap.

I’ve tried it with a TapGestureRecognizer on the charts parent UIView, which won’t fire the event once the chart is being shown, and with overriding the touchesBegan/Moved/Cancelled methods of UIView. Unfortunately, the touch is getting cancelled, so I can’t properly forward the tap event.

It would be nice to have a sChartTapped() or something like that in the future (as far as I see it, there isn’t anything in the current framework that uses a single tap anyway), but is there a workaround right now that I could use?

Cheers,
Max


Detecting single tap on chart with Xamarin SDK
#2

Hi Maximillian,

Thanks for getting in touch!

For your UITapGestureRecognizer to be picked up you have to implement the UIGestureRecognizerDelegate method “…shouldRecognizeSimultaneouslyWithGestureRecognizer:” to return YES and assign your UIGestureRecognizerDelegate to our UITapGestureRecognizer.

This can be done by adding the following code after you have created your chart:

for (UIGestureRecognizer *gesture in _chart.canvas.overlay.gestureRecognizers) {
    if([gesture isKindOfClass:[UITapGestureRecognizer class]]){
        gesture.delegate = self;
    }
}

More information on the UIGestureRecognizerDelegate can be found HERE.

Let me know if you have any questions.

Kind regards,
Andrew Polkinghorn


#3

Thanks Andrew, that was exactly what I was looking for. Very satisfied with that solution, highly appreciate your answer.

Regards,

Max