问题描述
我有一个 UIViewController
类,名为 AppController.h
, AppController.m
。我在那里有成千上万行代码,这是我在问之前没有测试过的唯一原因。有没有办法在 UIViewController
中使用 drawRect
?这样我就不必再做更多的委托和方法以及回调。我应该开始使用 drawRect
来处理我的绘图代码,但我没有,并且iPad上的核心图形严重滞后。所以,如果有任何方法在 UIViewController
中使用 drawRect
,请告诉我。
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 if there's any way to use drawRect
in a UIViewController
.
谢谢!
推荐答案
视图控制器自然有一个指向其视图的指针,所以当然你可以调用视图的 -setNeedsDisplay
方法,这将导致框架在适当的时间调用 -drawRect:
。虽然你想要在视图控制器中进行实际绘图,但是要确切地理解你所要求的内容有点难以理解?如果你尝试的话,你真的会反对这个框架 - 而是将绘图代码转移到你的视图类中。
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.
这篇关于从UIViewcontroller类调用drawRect的任何可能方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!