有什么可能的方法从 UIViewcontroller 类调用 drawRect 吗?

发布于 2024-12-07 11:34:22 字数 373 浏览 1 评论 0原文

我有一个名为 AppController.hAppController.mUIViewController 类。我在那里有数千行代码,这是我在询问之前没有测试它的唯一原因。有没有可能在 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.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

微暖i 2024-12-14 11:34:22

视图控制器自然有一个指向其视图的指针,因此您当然可以调用视图的 -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.

瀟灑尐姊 2024-12-14 11:34:22

您只需调用setNeedsDisplay,系统就会要求您在下一个适当的时间进行绘制。 (阅读:不要直接调用 drawRect:

如果您确实需要您请求的行为,那么只需在创建缓存位图或 CGImage 后调用 setNeedsDisplay code>/UIImage 是外部更新的(例如在控制器逻辑中),然后在请求绘制时绘制该图像。

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.

南巷近海 2024-12-14 11:34:22

您应该(重构/重写并)创建 UIView (而不是视图控制器)的子类,以便在需要进行任何绘图时使用正确的绘图上下文调用该视图的 drawRect 委托。如果可能的话,在没有适当的绘图上下文的情况下尝试进行绘图可能会非常缓慢。

从技术上讲,您可以分配并创建自己的位图绘制上下文,将其放入具有drawRect方法的自定义对象中,然后调用该drawRect和上下文。但是直接绘制到自定义绘图上下文中可能会更快。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文