在'ViewController *类型的对象上找不到属性'layer',其中ViewController的类型为GLKView,我也在我的opengl项目中导入以下文件
QuartzCore / QuartzCore.h
OpenGLES / ES2 / gl.h
OpenGLES / ES2 / glext.h
ViewController.h的代码
@interface ViewController : GLKViewController
{
CAEAGLLayer* eaglLayer;
}
@end
ViewController.m
@interface ViewController ()
@property (nonatomic, strong) EAGLContext *context;
@property (nonatomic, strong) GLKBaseEffect *baseEffect;
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.context = [[EAGLContext alloc] initWithAPI: kEAGLRenderingAPIOpenGLES2];
GLKView *view = (GLKView *) self.view;
view.context = self.context;
[EAGLContext setCurrentContext:self.context];
}
+ (Class)layerClass
{
return [CAEAGLLayer class];
}
- (void)createLayer
{
eaglLayer = (CAEAGLLayer *) self.layer;
eaglLayer.opaque = YES;
}
请告诉我我做错了什么?
答案 0 :(得分:0)
您需要参考视图,而不是控制器。
_eaglLayer = (CAEAGLLayer*) self.view.layer;
应该有效。