[英]ios OpenGl ES / GLKit - UIView as super and GLKView as sub view
Hello OpenGl ES expert, 您好OpenGl ES专家,
Have you ever added a GLKView on top of a UIView? 您是否曾经在UIView之上添加GLKView?
What I am trying out here is to use the standard OpenGl ES template from ios 6. I am using the GLKViewController, as everything is setup. 我在这里尝试的是使用ios 6中的标准OpenGl ES模板。我正在使用GLKViewController,因为一切均已设置。 Then I am trying to add the GLKViewController.view as a sub view to the view in another UIViewController - but the problem is that update() is not called on GLKViewController, and therefore no animation.
然后我试图将GLKViewController.view作为子视图添加到另一个UIViewController中的视图中-但问题是在GLKViewController上未调用update(),因此没有动画。 The first frame is rendered though.
第一帧虽然被渲染。
Do you have any idea on how to do this - or do I need to have bout UIView and GLKView in the same GLKViewController? 您对如何执行此操作有任何想法吗?还是我需要在同一GLKViewController中包含bout UIView和GLKView?
Thanks in advance. 提前致谢。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
UIViewController* topViewController = [[TopViewController alloc] init];
UIImageView* uiImageView = [[UIImageView alloc] initWithFrame:self.window.frame];
NSString *imgFrontFilepath = [[NSBundle mainBundle] pathForResource:@"front" ofType:@"png"];
UIImage* frontImg = [[UIImage alloc] initWithContentsOfFile:imgFrontFilepath];
[uiImageView setImage:frontImg];
[topViewController setView:uiImageView];
GLKViewController* glkViewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];
// glkViewController.paused = NO;
[[topViewController view] addSubview:[glkViewController view]];
self.viewController = topViewController; //[[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];
self.window.rootViewController = topViewController; //self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
I don't think you should be using GLKViewController if the root view is not a GLKView. 如果根视图不是GLKView,我不认为您应该使用GLKViewController。 You probably want to discard the GLKViewController and just use a GLKView -- you don't want to get into nesting viewControllers for something like this.
您可能想要丢弃GLKViewController,而仅使用GLKView -您不希望为此类嵌套嵌套viewControllers。 So you'd just have TopViewController as a regular UIViewController subclass, and somewhere in the setup code for TopViewController, you'd initialize all your OpenGL stuff and add a GLKView as a subview of topViewController.view.
因此,您只需要将TopViewController作为常规的UIViewController子类,并在TopViewController的安装代码中的某处,初始化所有OpenGL内容并添加GLKView作为topViewController.view的子视图。
Also, you definitely don't want to be doing all that stuff in application:didFinishLauncingWithOptions! 此外,您绝对不希望在application:didFinishLauncingWithOptions中做所有这些事情! It looks like it should be in TopViewController's viewDidLoad method.
看起来应该在TopViewController的viewDidLoad方法中。 You really want to stay out of the App Delegate as much as possible, and everything between
[[TopViewController alloc] init]
and self.viewController = topViewController;
您真的想尽可能地远离App Delegate,并且
[[TopViewController alloc] init]
在[[TopViewController alloc] init]
和self.viewController = topViewController;
should happen inside the TopViewController subclass. 应该发生在TopViewController子类中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.