简体   繁体   中英

draw line/point on existing UIView without drawRect?

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?

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

您可以使用setNeedsDisplayInRect:绘制视图的一部分。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM