views:

458

answers:

2

I have a line graph I've drawn in Quartz, and a UIView 'bubble' that I'd like to ideally pop up when the user touches the single plot line, and moves their finger along it. The bubble displays some extra graph information.

I'd like to 'attach' the UIView to the CGPath plot, but I'm having trouble conceptually figuring out the best way to do this. I know you can animate a view along a CGPath, but this doesn't seem to work for me, because the user needs to 'scrub' along the graph themselves with their finger rather than any automatic animation.

Does anyone have any suggestions of a good approach?

+1  A: 

Maybe you don't need to animate it. Touch events fly by pretty quickly -- maybe if you just move the view to the appropriate location relative to the touch without animation the move will be smooth enough. If that's not good enough, you'll have to animate along the graph segment from the current location of the view (see CALayer presentationLayer) to the desired location. The key is that you'll be animating every time you receive a touch event (and any previous animations would be cancelled).

Neil Mix
A: 

Like Neil said, your best bet is to just move with the touch events, it will look smooth if all you're doing is moving a view. Use [aTouch locationInView:view] to get the touch's position, then find the closest point on the path (maybe use the x value and look up the y value on the path for the x).

David Kanarek