How to access drawrect method from UIViewController?

梦想的初衷 提交于 2019-12-11 18:10:12

问题


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

In it, inside viewWillAppear i have

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

Inside gameLoop method, i have

[[self view] setNeedsDisplay];

Problem:

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

Question:

  • 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?

回答1:


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.)



来源:https://stackoverflow.com/questions/8235967/how-to-access-drawrect-method-from-uiviewcontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!