开发者

Any possible way to call drawRect from a UIViewcontroller class?

I have a UIViewController class called AppController.h, AppController.m. I have thousands of lines of code in there, and that is the only reason why I didn't test this before I asked it. Is there any possible way to use drawRect in a UIViewController? that way I wouldn't have to make more delegates and methods and callbacks. I should have started off using drawRect to handle my drawing code, but I didn't, and there's severe lag with core graphics on the iPad. So, please let me know 开发者_StackOverflow社区if there's any way to use drawRect in a UIViewController.

Thanks!


A view controller naturally has a pointer to its view, so of course you can call the view's -setNeedsDisplay method, which will cause the framework to call -drawRect: at the appropriate time. It's a little hard to understand exactly what you're asking, though... are you hoping to do the actual drawing in your view controller? You'd really be working against the framework if you try that -- move the drawing code into your view class instead.


you just call setNeedsDisplay and you will be requested to draw at the next appropriate time. (read: don't call drawRect: directly)

if you really need the behaviour you request, then just call setNeedsDisplay after creating a cached bitmap or CGImage/UIImage which is externally updated (e.g. in your controller logic) and then just draw that image when requested to draw.


You should (refactor/rewrite and) create a subclass of a UIView (not a view controller) in order to have that view's drawRect delegate called with a proper drawing context when you need to do any drawing. Trying to draw without a proper drawing context can be painfully slow, if at all possible.

Technically, you could allocate and create your own bitmap drawing context, put in in a custom object with a drawRect method, and call that drawRect and context. But then it might be just faster to just draw directly into your custom drawing context.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜