在多个ViewControllers

时间:2018-01-11 18:24:05

标签: ios swift singleton arkit

我想构建一个应用,用户可以在不同的AR视图之间滑动,这些视图使用不同的内容但在同一个AR会话中 - 因此他们不需要每次都搜索平面/功能

我试图通过单例将ARSCNView从一个ViewController传递给另一个ViewController。但它给了我错误:

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key sceneView.'

在这种情况下使用正确的模式是什么?

MainViewController:

extension MainViewController: ARSCNViewDelegate, ARSessionDelegate 
{
    func initAR(){
        ArSceneView.delegate = self
        ArSceneView.scene = scene
        ArSceneView.debugOptions = [ARSCNDebugOptions.showFeaturePoints]
        MainViewController.manager.ArSession=ArSceneView
    }

    override func viewWillAppear(_ animated: Bool) {
        let configuration = ARWorldTrackingConfiguration()
        ArSceneView.session.run(configuration)
    }

}

AnotherViewController:

class AnotherViewController:  {
    override func viewDidLoad() {
        MainViewController.manager.ArSession.delegate = self
    }
}
编辑:我找到了一个解决方法 - 如果你想在不同的ViewControllers上使用相同的AR会话,可以随意使用UIPageViewController和SCNView,然后它在连接到UIPageViewController的不同视图中保持不变。

1 个答案:

答案 0 :(得分:0)

本主题本身很有趣。所以我尝试在prepareForSeague中简单地传递了一个从一个到另一个viewcontroller的会话。它切换没有任何错误,但sceneview是空的。现在我不确定它是重置还是全新会话开始。我真的很想知道你的工作。

对于您的问题 - 如果您的AnotherViewController中没有任何其他特定功能,您可以在内容之间滑动。