如何在不同时间在drawRect中绘制图形对象? [英] How to draw graphic objects within drawRect at different times?

查看:58
本文介绍了如何在不同时间在drawRect中绘制图形对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于特定的控制器类,我需要绘制一个网格(该网格指的是每天的时间表,该时间表每天(有时是每小时)都会发生变化.)一段时间后,根据用户的操作,我需要用我原来的网格时没有的更新的计划数据填充该网格.

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 the user, I need to fill that grid with updated schedule data that I did not have when I was doing the original grid.

我的问题是:由于我在viewDidLoad时不知道所选的日期,这是否意味着我必须重新绘制整个网格以及新的每日计划数据? (这是我可以想到的在drawRect中绘制所有内容的唯一方法)还是可以调用drawRect的 outside 方法来绘制每日时间表?还是有另一种更好的方法?

My question is: since I don't know the selected day at the time the viewDidLoad, does this mean I have to re-draw the entire grid again, along with the new daily schedule data? (that's the only way I can think of to get everything drawn in the drawRect) Or can I call a method outside of drawRect to draw the daily schedule? or is there another, better way of doing this?

推荐答案

您没有指定这是iOS还是Mac,这可能会在很小程度上影响您能够对此做出的假设.但通常,视图的drawRect方法至少应重新绘制提供的矩形内的所有内容(线索在方法名称中).而且,从广义上讲,这是管理此类绘图的地方,尽管您当然可以将代码分解为其他方法,以使其更加清晰和井井有条.

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.

这篇关于如何在不同时间在drawRect中绘制图形对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆