如何从UIViewController访问drawrect方法? [英] How to access drawrect method from UIViewController?

查看:98
本文介绍了如何从UIViewController访问drawrect方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Xcode 4.2,并且有一个UIViewController代表场景之一。

I am using Xcode 4.2 and have a UIViewController representing one of the scenes.

在其中,我有 viewWillAppear

[NSTimer scheduledTimerWithTimeInterval: FramesPerSecond target:self 
selector:@selector(gameLoop) userInfo:nil repeats:YES];

gameLoop 方法内部,我有

[[self view] setNeedsDisplay];

问题:

drawRect 方法未调用(据我了解,应从 setNeedsDisplay

drawRect method is not being called (As i understand it it should be called from setNeedsDisplay

问题:


  • 是否可以定义<$ c UIViewController 类中的$ c> drawRect 方法,因此应该如何声明它?在 UIView上调用它据我了解。

  • 如果不可能,您将如何使用Xcode 4.2解决这种情况?

  • Is it possible to define drawRect method inside a UIViewController class and is so how should one declare it? It is called on a UIView as i understand it.
  • If is it not possible, how would you address the situation using Xcode 4.2?

推荐答案

否。您需要将UIViewController控制的UIView子类化。

No. You would need to subclass the UIView that the UIViewController controls.

(作为一个附带说明,计时器并不是游戏循环的好选择,因为您无法获得完全可预测的计时。)

(As a side note, timers aren't great for game loops because you don't get totally predictable timing.)

这篇关于如何从UIViewController访问drawrect方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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