How to draw graphic objects within drawRect at different times?

前端 未结 2 1833
轮回少年
轮回少年 2021-01-27 17:21

For a particular controller class, I need to draw a grid (the grid refers to a daily schedule, which changes each day, sometimes each hour.). Some time later, upon an action by

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-27 17:52

    You don't specify whether this is iOS or Mac, which might very marginally affect what assumptions you are able to make about this. But in general a view's drawRect method should at least redraw everything within the supplied rectangle (the clue is in the method name). And, broadly speaking, that is the place to manage such drawing, though of course you can break the code up into other methods for clarity and organisation.

    Unless your grid is incredibly dense, it is unlikely that this redraw will have noticeable impact on performance. Failing to redraw needed content in actually dirty regions would be a much worse situation.

提交回复
热议问题