我正在用画布做游戏。这个游戏因为最高档次而被删减,我尝试过SafeAreaLayoutGuide,但是什么也没发生。请看下面的代码,让我知道我做错了什么。
-(void) createGLView {
//create our openglview and size it correctly
OpenGLView *glView = [[OpenGLView alloc] initWithFrame:self.appDelegate.initFrame];
self.view = glView;
self.appDelegate.canvas = glView;
core_init_gl(1);
glView.backgroundColor = [UIColor redColor];
glView.translatesAutoresizingMaskIntoConstraints = NO;
[glView.leadingAnchor constraintEqualToAnchor:glView.safeAreaLayoutGuide.leadingAnchor].active = YES;
[glView.trailingAnchor constraintEqualToAnchor:glView.safeAreaLayoutGuide.trailingAnchor].active = YES;
[glView.topAnchor constraintEqualToAnchor:glView.safeAreaLayoutGuide.topAnchor].active = YES;
[glView.bottomAnchor constraintEqualToAnchor:glView.safeAreaLayoutGuide.bottomAnchor].active = YES;
int w = self.appDelegate.screenWidthPixels;
int h = self.appDelegate.screenHeightPixels;
tealeaf_canvas_resize(w, h);
NSLOG(@"{tealeaf} Created GLView (%d, %d)", w, h);
}红色在顶端凹口内。我的意思是全屏。如何解决这个问题?
发布于 2019-03-12 16:48:47
你需要有一个全屏的父视图。然后,您可以将OpenGLView添加为子视图,并将其约束连接到父视图的safeAreaLayoutGuide。
- (void)createGLView {
OpenGLView *glView = [[OpenGLView alloc] initWithFrame:self.appDelegate.initFrame];
[self.view addSubview:glView];
self.appDelegate.canvas = glView;
core_init_gl(1);
glView.backgroundColor = [UIColor redColor];
glView.translatesAutoresizingMaskIntoConstraints = NO;
[glView.leadingAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.leadingAnchor].active = YES;
[glView.trailingAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.trailingAnchor].active = YES;
[glView.topAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.topAnchor].active = YES;
[glView.bottomAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.bottomAnchor].active = YES;
int w = self.appDelegate.screenWidthPixels;
int h = self.appDelegate.screenHeightPixels;
tealeaf_canvas_resize(w, h);
NSLOG(@"{tealeaf} Created GLView (%d, %d)", w, h);
}https://stackoverflow.com/questions/55115894
复制相似问题