我有一个非常简单的设置记住,有一个GLViewViewController上的一个mainViewController。这个想法是让我的GLKViewController放在一个盒子里,在mainViewController上占据屏幕的1/3。这可以看到下面:GLKViewController添加到子视图 - GLKView上下文导致崩溃
说白盒子是我自己的自定义GLKViewController与后续代码:
boxViewController.h
//boxViewController.h
#import <UIKit/UIKit.h>
#import <GLKit/GLKit.h>
@interface boxViewController : GLKViewController
@end
boxViewController.m
//boxViewController.m
#import "boxViewController.m"
@interface boxViewController() { }
@property (strong, nonatomic) EAGLContext *context;
@end
@implementation boxViewController
-(void)viewDidLoad {
[super viewDidLoad];
self.context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
if (!self.context) {
NSLog(@"Failed to create ES context");
}
GLKView *view = (GLKView *)self.view;
// view.context = self.context;
view.drawableDepthFormat = GLKViewDrawableDepthFormat24;
}
@end
论viewDidLoad
我只需拨打boxViewController这样我mainViewController
:
boxViewController* box = [[boxChartViewController alloc] init];
box.view.layer.frame = CGRectMake(10, 50, self.view.frame.size.width-20, self.view.frame.size.height/3);
[self.view addSubview:box.view];
它可以完美运行。
请注意,在我的boxViewController.m我有view.context = self.context
注释掉。如果取消它的注释,我的应用程序崩溃而没有任何错误消息(它在objc_msgSend
汇编代码中的EXC_BAD_ACCESS
[第8行是特定的])。
我做错了什么,当我设置上下文应用程序崩溃?从所有的教程中我都注意到他们有相同的设置,除了没有在其他控制器上设置控制器。虽然我不明白为什么GLKViewController不能在另一个控制器上构建,所以我不认为这是问题所在。
我有同样的问题试图将AdBannerView添加作为视图的孩子。不知道广告横幅是否设计为与控制器配合使用。很明显,GLKView对没有控制器的子视图并不满意。我在这里找不到有关确切问题的更多信息。你能获得更多信息吗? – Shammi 2014-05-08 14:24:52
嗨@Shammi,我不确定它如何与集成AdBannerView和GLKView一起工作。你可能想问一个关于它的问题,这样其他人可以提供帮助。 – 2014-05-09 13:07:02