gpt4 book ai didi

ios - 嵌套 GLKViewController

转载 作者:行者123 更新时间:2023-11-29 03:31:14 24 4
gpt4 key购买 nike

我试图将 GLKView 嵌套在 UIView XIB 中。基本上按照这里的步骤: Nested GLKView and GLKViewController

我的CustomOpenGLController.xib只是一个GLKView

我的MainViewController.xib有一个GLKView subview 。

在我的MainViewController.xib中,我有一个带 socket 的GLKView:

 @property (weak, nonatomic) IBOutlet GLKView *theSubView;

然后在MainViewController.m中我执行以下操作:

- (void)viewDidLoad
{
[super viewDidLoad];

NSLog(@"viewDidLoad");
subviewController = [[CustomOpenGLController alloc] initWithNibName:@"CustomOpenGLController" bundle:nil];
subviewController.view.frame = _theSubView.frame;
[subviewController setView:self.theSubView];
[self.theSubView setNeedsDisplay];
[subviewController didMoveToParentViewController:self];
}

这会导致调用 CustomOpenGLControllerviewDidLoad ,从而执行以下操作:

CustomOpenGLController.h

@interface CustomOpenGLController : GLKViewController <GLKViewControllerDelegate, GLKViewDelegate>
{
@private
GLKBaseEffect *effect;
}

#pragma mark GLKViewControllerDelegate
- (void)glkViewControllerUpdate:(GLKViewController *)controller;

#pragma mark GLKViewDelegate
- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect;

@end

CustomOpenGLController.m

- (void)viewDidLoad
{
[super viewDidLoad];

NSLog(@"viewDidLoad");

EAGLContext *aContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];

GLKView *glkView = (GLKView *)self.view;
glkView.delegate = self;
glkView.context = aContext;

glkView.drawableColorFormat = GLKViewDrawableColorFormatRGBA8888;
glkView.drawableDepthFormat = GLKViewDrawableDepthFormat16;
glkView.drawableMultisample = GLKViewDrawableMultisample4X;

self.delegate = self;
self.preferredFramesPerSecond = 30;

effect = [[GLKBaseEffect alloc] init];

glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
}

问题是委托(delegate)glkViewControllerUpdateglkViewdrawInRect未被调用。

如果我添加 CustomOpenGLController 作为 subview (而不是 setView 调用),则 glkView drawInRect 会被调用一次。如果单独使用 CustomOpenGLController 作为 View ,那么一切都会完美运行。

但是我需要将此 CustomOpenGLController 嵌入到普通 View Controller 中。

更新

如果我将 MainViewController.mviewDidLoad 修改为以下内容,那么它可以工作,但它只渲染 1 帧,然后停止调用 glkView drawInRect :

- (void)viewDidLoad
{
[super viewDidLoad];

NSLog(@"viewDidLoad ControllerView");
subviewController = [[ControllerOpenGLViewController alloc] initWithNibName:@"ControllerOpenGLViewController" bundle:nil];
subviewController.view.frame = _theSubView.frame;

subviewController.view.opaque = NO;
subviewController.view.backgroundColor = [UIColor clearColor];

[self.view addSubview:subviewController.view];
[subviewController.view setNeedsDisplay];

NSLog(@"Done viewDidLoad ControllerView");
}

这奇怪地渲染了 1 帧然后停止。而且 glkViewControllerUpdate 永远不会被调用。

最佳答案

您将 CustomOpenGLController 设置为子 ViewController,但您从未在 MainViewController viewDidLoad 中调用 addChildViewController。你的问题可能来自于此

关于ios - 嵌套 GLKViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19756488/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com