Search code examples
iosios-charts

Adding a second PanGestureRecognizer, or equivalent workaround?


I'm working with the ios-charts library and I need to do some special logic when the user stops panning over the chart. The library defines the panGestureRecognized method as fileprivate, so I can't subclass/override it. It also doesn't provide any sort of protocol for listening to the pan gestures.

How can I listen to the pan gestures without interrupting the functionality of the chart?

I've considered putting a view on top of the chart and adding a gesture recognizer to that, but it swallows the events and disrupts the regular chart functionality.


Solution

  • The default behavior of any gesture recognizer is to block touches to its subviews. You can change this behavior by writing:

    panGesture.cancelsTouchesInView = NO;
    

    To get even more control over simultaneous pan gesture gesture recognition, set your own class as the delegate for the gesture recognizer and use this method:

    - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
    

    Just return YES in this method if you just care about the two pan gestures to work simultaneously.