0

在“ViewController *”类型的对象上找不到属性“层”,其中 ViewController 的类型为 GLKView,而且我正在我的 opengl 项目中导入以下文件

QuartzCore/QuartzCore.h

OpenGLES/ES2/gl.h

OpenGLES/ES2/gext.h

ViewController.h 的代码

@interface ViewController : GLKViewController

{

    CAEAGLLayer* eaglLayer;

}

@结尾

视图控制器.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;
}

请告诉我我做错了什么?

错误线在控制器中添加了 GLKView

4

1 回答 1

0

您需要参考视图,而不是控制器。

_eaglLayer = (CAEAGLLayer*) self.view.layer;

应该管用。

于 2016-03-03T19:32:43.560 回答