OGeek|极客世界-中国程序员成长平台

标题: ios - 将 SceneKit 场景文件添加到 View Controller [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 16:25
标题: ios - 将 SceneKit 场景文件添加到 View Controller

这是我第一次将 SceneKit 添加到我的应用程序中, 我创建了一个名为“StarScene.scn”的 SceneKit 文件,我想将它显示到我的 StarViewController 中,它不起作用,我只是不知道如何使它正确。请帮忙。编码和截图如下。非常感谢。

- (void)viewDidLoad
{

    [super viewDidLoad];

    SCNView *myView = (SCNView *)self.view;
    myView.scene = [SCNScene sceneNamed"StarScene.scn"];
    myView.allowsCameraControl = YES;
    myView.autoenablesDefaultLighting = YES;
    myView.backgroundColor = [UIColor lightGrayColor];

}

enter image description here

enter image description here

enter image description here



Best Answer-推荐答案


从我在 Interface Builder 屏幕截图中看到的,似乎 SCNView 实际上是 Controller View 的 subview ,而不是 Controller View 本身。你的代码会崩溃吗? (这将确认 self.view 不是 SCNView 而是简单的 UIView)。

您可能希望将 SCNView 作为 Controller 的 View ,或者创建一个 IBOutlet 以便您可以从 View Controller 检索和操作 SceneKit View 。

关于ios - 将 SceneKit 场景文件添加到 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32797937/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4