ios - 如何修复 SafeAreaLayoutGuide

标签 ios objective-c xcode safearealayoutguide

我正在用 Canvas 制作游戏。游戏因为一流而被剪裁,我试过 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);
}

红色进入顶部槽口。我的意思是全屏。如何解决?

最佳答案

您需要有全屏父 View 。然后您可以将 OpenGLView 添加为 subview ,并将其约束连接到父 View 的 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);
}

关于ios - 如何修复 SafeAreaLayoutGuide,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55115894/

相关文章:

ios - 如何在执行 segue 之前获取 UITableView 中最后选定的行

ios - 如何让 iPhone X home bar 横屏双击?

ios - 我可以将 Xcode4 与两个未链接的独立 Apple 开发者帐户一起使用吗?

ios - 如何向 Xcode 中的 XCTestCase 单元添加辅助方法?

ios - 无法计算 iOS App 上的文件大小

ios - 下载 PDF 并保存到 iPhone 中的 "Files",而不是应用程序数据,Swift

iOS 9 - 网络可达性变化导致 View 卡住 - 不是崩溃

ios - NSLayoutConstraint.constraintsWithVisualFormat 在 Swift 2.0 中的 options 参数中传递 nil

objective-c - iOS 6 - UIWebView loadHTMLString 无法正常工作

objective-c - 在 Objective-C 中模拟方法重载