菜鸟教程小白 发表于 2022-12-11 18:14:23

ios - ARKit session 已暂停且未恢复


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

<pre><code> override func viewWillDisappear(_ animated: Bool) {
      super.viewWillDisappear(animated)

      // Pause the view&#39;s session
      sceneView.session.pause()
    }
</code></pre>

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

<pre><code>override func viewWillAppear(_ animated: Bool) {
      super.viewWillAppear(animated)

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

      // Run the view&#39;s session
      sceneView.session.run(configuration)
    }
</code></pre>

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

<p>我将 viewDidAppear 代码更新为以下内容。它仍然卡在相机屏幕上,图像卡住。 </p>

<pre><code>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&#39;s session
            sceneView.session.run(configuration)
      }


    }
</code></pre></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>不确定为什么您的 session 没有恢复,但是...这通常不是您想要的情况。</p>
<p>Apple 的 ARKit 示例代码随附的自述文件中的注意事项(附在 <a href="https://developer.apple.com/videos/play/wwdc2017/602/" rel="noreferrer noopener nofollow">WWDC17 session on ARKit</a> 上):</p>
<blockquote>
<p><strong>Avoid interrupting the AR experience.</strong> If the user transitions to another fullscreen UI in your app, the AR view might not be an expected state when coming back.</p>
<p>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 <code>SettingsViewController</code> and <code>VirtualObjectSelectionViewController</code> classes use popover presentation.</p>
</blockquote>
<p>更详细一点:如果您暂停 session ,当您的用户不在另一个全屏 ViewController 中时,它不会跟踪世界。这意味着当您恢复时,放置在场景中的任何虚拟内容都不会位于您离开它的位置(相对于相机)。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - ARKitsession 已暂停且未恢复,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/45021584/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/45021584/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - ARKit session 已暂停且未恢复