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 method 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?

Venk
  • 5,949
  • 9
  • 41
  • 52
plusz
  • 224
  • 2
  • 16

2 Answers2

1

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
  • 90,870
  • 19
  • 190
  • 224
0

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

Rits
  • 5,105
  • 4
  • 42
  • 53
  • In that case, you also need to use the rect parameter in drawRect: to only draw in that rect... – gcamp Oct 26 '10 at 13:35
  • 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 Oct 26 '10 at 13:43