首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何修复SafeAreaLayoutGuide

如何修复SafeAreaLayoutGuide
EN

Stack Overflow用户
提问于 2019-03-12 15:10:06
回答 1查看 113关注 0票数 1

我正在用画布做游戏。这个游戏因为最高档次而被删减,我尝试过SafeAreaLayoutGuide,但是什么也没发生。请看下面的代码,让我知道我做错了什么。

代码语言:javascript
复制
-(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);
}

红色在顶端凹口内。我的意思是全屏。如何解决这个问题?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-03-12 16:48:47

你需要有一个全屏的父视图。然后,您可以将OpenGLView添加为子视图,并将其约束连接到父视图的safeAreaLayoutGuide

代码语言:javascript
复制
- (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);
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55115894

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档