views:

54

answers:

2

I created line chart. Now I need to display point on this chart when I tap the screen. What would be the best method? Do I need to call drawRect again, draw whole chart with marked point?

I'm thinking about something like transparent layer over the chart UIView. Can I create another transparent UIView and put it on the position of my chart?

A: 

You can draw a portion of your view using setNeedsDisplayInRect:.

Rits
In that case, you also need to use the rect parameter in drawRect: to only draw in that rect...
gcamp
hm... but will will reauire to calculate what is chart shape in this rect, and after touchesEnded I need to clear this area. Is it good idea to create another UIView in the same rect?
plusz
A: 

Since all drawing is done in a view's drawRect: you can only optimize your chart's drawing so it can be made to update only a part of it and use setNeedsDisplayInRect: (passing the area where the marker should be).

Or you create another UIView subclass that is layered atop of your chart and that does nothing but drawing the markers on a transparent background. Probably easier and faster to implement. It also would have another benefit:

If you make that view only as big as the bounding box of the marker you could also easily animate it, like fading it in and out. Or letting it rotate a little (to see the effect I have in mind, select the "Help" menu in Mac OS X, type something in the search field like "a", and see the marker next to a menu item move a little around a spot).

DarkDust
I decided to create new UIView on the top of previous.
plusz