ios - 如何修复 SafeAreaLayoutGuide
问题描述
我正在用画布制作游戏。游戏因为一流而被剪辑,我试过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);
}
红色进入一流水平。我是说全屏。如何解决这个问题?
解决方案
您需要有一个全屏父视图。然后您可以添加OpenGLView
as 子视图并将其约束连接到父视图的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);
}
推荐阅读
- javascript - 未捕获的类型错误:无法读取 null 的属性“标题”-本地存储
- emacs - 将 evil-leader 与 use-package 一起使用:错误 (use-package): evil-leader/:config: Invalid function: (global-evil-leader-mode)
- sql - 如何获得正确的累积余额?
- typescript - 你如何阻止打字稿复制 src 文件夹
- c# - 如何使图像与窗体大小匹配
- reactjs - 如何解决 No QueryClient set,使用 QueryClientProvider 在 React Query v3 中设置一个
- r - R - 如果在列表中找不到,则更改值
- angular-cli - BitBucket Pipelines 无法构建生产 Angular 代码(暂存和本地机器工作)
- docker - 在 MERN 应用程序中找不到 Dockerfile
- python - 如何在 OpenTURNS 中使用 BIC 对分布列表进行排名?