ios – ARKit会话已暂停且未恢复

在我的ARKit应用程序中,我提出了一个模态窗口.当我关闭模态并返回到ARSCNView时,我发现由于此代码会话暂停:
override func viewWilldisappear(_ animated: Bool) {
        super.viewWilldisappear(animated)

        // Pause the view's session
        sceneView.session.pause()
    }

当我关闭模态并返回到ARKit相机视图屏幕时,此代码被触发:

override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)

        // Create a session configuration
        let configuration = ARWorldTrackingSessionConfiguration()

        // Run the view's session
        sceneView.session.run(configuration)
    }

但是这段代码永远不会恢复会话.屏幕在其读取的最后一张图像上完全冻结.有任何想法吗?

我将viewDidAppear代码更新为以下内容.它仍然卡在相机屏幕上,图像被冻结.

override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)

        // Create a session configuration
        let configuration = ARWorldTrackingSessionConfiguration()

        sceneView.session.delegate = self

        if self.isPaused {
            sceneView.session.run(sceneView.session.configuration!)
        } else {
            // Run the view's session
            sceneView.session.run(configuration)
        }


    }

解决方法

不确定为什么你的会话没有恢复,但是…这通常不是你想要的情况.

请注意随附Apple的ARKit示例代码(附于WWDC17 session on ARKit)的自述文件

Avoid interrupting the AR experience. If the user transitions to another fullscreen UI in your app,the AR view might not be an expected state when coming back.

Use the popover presentation (even on iPhone) for auxiliary view controllers to keep the user in the AR experience while adjusting settings or making a modal selection. In this example,the SettingsViewController and VirtualObjectSelectionViewController classes use popover presentation.

更详细一点:如果你暂停会话,当你的用户离开不同的全屏视图控制器时,它将不会跟踪世界.这意味着当您恢复时,放置在场景中的任何虚拟内容都不会位于您离开它的位置(相对于摄像机).

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...