recognizing double-tapping bars, ignoring single-taps - is there a better way?

60 views
Skip to first unread message

fedonev

unread,
May 19, 2012, 6:31:04 AM5/19/12
to coreplot...@googlegroups.com
Hello All,

I have an iOS project that implements bar charts with several types of user interaction.  Everything works fine.  Swipe to pan with axis constraints, pinch zooming on a single axis (CPTPlotSpaceDelegate) and selecting a bar (barWasSelectedAtRecordIndex).  Excellent, so far so good.

One problem --  it was very easy with all the swiping and pinching going on to inadvertently trigger a new bar selection.  So I set about seeing how I could ignore single taps on bars and just handle double-taps.  To do this, I have to (a) have a hook to the event to count taps and (b) discover the index of the selected bar.

I started with the CPTPlotSpaceDelegate event handling methods.  shouldHandlePointingDeviceDownEvent worked great on double-taps outside bars, but did not respond to taps inside the bars.  Peeking into CPTBarPlot.m, I found that -- quite reasonably -- this is by design.  If its delegate implements barWasSelectedAtRecordIndex, CPTBarPlot.m handles the pointingDeviceDown event by identifying the tapped bar and messaging the delegate.  This makes perfect sense, but left me with the problem of finding a way to ignore single taps.

In the end I could not find a way to get both (a) and (b) using the API.  So I met my needs by modifying CPTBarPlot.m (ever so slightly) to invoke barWasSelectedAtRecordIndex only on double taps.   (-(BOOL)pointingDeviceDownEvent:(id)event atPoint:(CGPoint)interactionPoint) .  Works like a charm, but it meant fiddling with the framework.

After all that, my question is - is there a better, i.e. non-invasive way of solving this problem?

Last comment - this is my first post so let me express my thanks to the developers of this wonderful framework.   Great work, thanks for your efforts.

David





Eric

unread,
May 19, 2012, 9:09:00 AM5/19/12
to coreplot...@googlegroups.com
We have added additional plot delegate methods that include the event since the 1.0 release. The one for bar plots is:

-(void)barPlot:(CPTBarPlot *)plot barWasSelectedAtRecordIndex:(NSUInteger)index withEvent:(CPTNativeEvent *)event;


If you modify CPTGraphHostingView to pass along the event when the touch count is 1 or 2 instead of just 1, you can use this plot delegate method and only perform your response action if the touch count in the event is 2.

Eric

fedonev

unread,
May 20, 2012, 10:28:32 AM5/20/12
to coreplot...@googlegroups.com
Eric,

Wonderful, thanks.  I have pulled the latest version and the new method works like a charm.

Thanks again.

David
Reply all
Reply to author
Forward
0 new messages