开发者

draw line/point on existing UIView without drawRect?

I crea开发者_如何学Goted 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?


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).


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜