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

标题: ios - ARKit session 已暂停且未恢复 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 18:14
标题: ios - ARKit session 已暂停且未恢复

在我的 ARKit 应用程序中,我展示了一个模态窗口。当我关闭模式并返回 ARSCNView 时,我发现 session 由于以下代码而暂停:

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

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

当我关闭模式并返回 ARKit 相机 View 屏幕时,此代码会被触发:

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

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

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

但是这段代码永远不会恢复 session 。屏幕在它读取的最后一个图像上完全卡住。有什么想法吗?

我将 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)
        }


    }



Best Answer-推荐答案


不确定为什么您的 session 没有恢复,但是...这通常不是您想要的情况。

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.

更详细一点:如果您暂停 session ,当您的用户不在另一个全屏 View Controller 中时,它不会跟踪世界。这意味着当您恢复时,放置在场景中的任何虚拟内容都不会位于您离开它的位置(相对于相机)。

关于ios - ARKit session 已暂停且未恢复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45021584/






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