Search code examples
iostouchcore-plotdetection

Methods to detect touches on a coreplot graph


I've been looking into coreplot. I've got a graph plotted, but I'm looking to detect touches on it in a similar way to "touchesBegan" "touchesMoved" etc.

I've seen a lot of very vague stuff about the methods used such as

 "- plotSpace:shouldHandlePointingDeviceDownEvent:atPoint:"

But I'm getting nowhere with them. Any tips?


Solution

  • In your header file, add the CPTPlotSpaceDelegate

    @interface MyCorePlotView : UIView <CPTPlotDataSource, CPTPlotSpaceDelegate> {
        ...
    }
    

    In your implementation file add the delegate method

    -(BOOL)plotSpace:(CPTPlotSpace *)space shouldHandlePointingDeviceDownEvent:(id)event atPoint:(CGPoint)point
    {
        // Handle down event
    }
    

    When the user taps the plot area you will receive the plotSpace:shouldHandlePointingDeviceDownEvent: and then you can take appropriate action.

    Look in the CPTPlotSpace.h for other delegate methods you might want to use as well.