如何修复 SafeAreaLayoutGuide
Posted
技术标签:
【中文标题】如何修复 SafeAreaLayoutGuide【英文标题】:How to fix SafeAreaLayoutGuide 【发布时间】:2019-03-12 07:10:06 【问题描述】:我正在用画布制作游戏。游戏因为一流而被剪辑,我试过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);
红色进入***。我是说全屏。如何解决?
【问题讨论】:
如果我理解正确,您需要将 glView 捏到其超级视图的安全区域。像这样 [glView.leadingAnchor constraintEqualToAnchor:self.safeAreaLayoutGuide.leadingAnchor].active = YES; 【参考方案1】:您需要有一个全屏父视图。然后您可以将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);
【讨论】:
以上是关于如何修复 SafeAreaLayoutGuide的主要内容,如果未能解决你的问题,请参考以下文章