本文介绍了将GLKView嵌套到UIViewController中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我正在尝试在UIViewController中使用GLKView,我的代码看起来像这样I'm trying to use GLKView in UIViewController, my code looks like this CustomViewController.hCustomViewController.h#import <UIKit/UIKit.h>#import <GLKit/GLKit.h>@interface CustomViewController : UIViewController{ NSString * name;}@property NSString * name; CustomViewController.mCustomViewController.m#import "CustomViewController.h"@interface CustomViewController ()@end@implementation CustomViewController@synthesize name;- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{ self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self;}- (void)viewDidLoad{ [super viewDidLoad]; // Do any additional setup after loading the view. EAGLContext * context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; CGRect mainScreen = [[UIScreen mainScreen] bounds]; GLKView * viewGL = [[GLKView alloc] initWithFrame:CGRectMake(mainScreen.size.width / 2, mainScreen.size.height / 2, 50, 50)]; viewGL.context = context; [self.view addSubview:viewGL];}- (void)viewDidUnload{ [super viewDidUnload]; // Release any retained subviews of the main view.}- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{ return (interfaceOrientation == UIInterfaceOrientationPortrait);}@end如何定义抽奖/ GLKView的渲染方法?我在哪里可以初始化OpenGL?有什么建议吗?How can I define the draw/render method of GLKView? and where can I init OpenGL? Any suggestions?推荐答案在 viewDidLoad 中初始化OpenGL,就像你一样'目前正在做。Initialize OpenGL in your viewDidLoad, just as you're currently doing.看一下将视图控制器注册为GLKView的代表。每当需要重绘时,代理的 glkView:(GLKView *)视图drawInRect:方法将被调用。Take a look at registering your view controller as the GLKView's delegate. The delegate's glkView:(GLKView *)view drawInRect: method will be invoked whenever a redraw is required. 本教程可能有所帮助。 这篇关于将GLKView嵌套到UIViewController中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 阿里云证书,YYDS! 05-23 12:18