Swift ARKit如何完全杀死ARSession? [英] Swift ARKit How do you fully kill an ARSession?

查看:284
本文介绍了Swift ARKit如何完全杀死ARSession?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个运行ARSessionARSCNView.您可以使用session.pause()暂停会话,但是仍然有效,它将使会话继续运行.我尝试通过从其超级视图中删除ARSCNView来解除分配. ARSCNView确实已取消分配,但ARSession之后仍在运行!!您也不能将nil分配给ARSession.我可以看到ARSessionDelegate

I have an ARSCNView running an ARSession. You can pause the session with session.pause() sure, but that still in effect, leaves the session running. I have tried deallocating the ARSCNView by removing it from its superview. The ARSCNView indeed deallocates but the ARSession is still running afterwards!! You can't assign nil to ARSession either. I can see the ARSessionDelegate's

func session(_ session: ARSession, didUpdate frame: ARFrame) 

仍在被呼唤!

完成后如何用ARKit彻底擦拭干净?

How do you completely wipe the slate clean with ARKit once you have finished with it?

有可能吗?

推荐答案

目前,您还不能这样做.

但是,有一种解决方法:将ARSCNView设为一次性.

However, there is a work-around: you make the ARSCNView disposable.

离开AR时,请先暂停ARSession.然后取消分配整个ARSCNView层次结构&将ARSCNView设置为nil以获得良好的效果.重建整个ARSCNView层次结构,并在需要返回到AR时开始新的会话.

On leaving AR, first pause the ARSession. Then deallocate the entire ARSCNView hierarchy & set ARSCNView to nil for good measure. Rebuild the entire ARSCNView hierarchy and start a new session whenever you need to go back to AR.

var ARview: ARSCNView?

func punchTheClown() {

    ARView?.session.pause()
    ARView?.removeFromSuperview()
    ARView = nil

}

应用程序的其他非AR区域通常位于与ARSCNView处于同级的单独视图层次结构中.我期待Apple提供实际的stopSession()功能,因此我们所有人都可以在此期间不再需要对TheClown打孔.

Other non-AR areas of your app would typically be in a separate view hierarchy at the same sibling level as your ARSCNView. I look forward to Apple providing an actual stopSession() function, so we can all stop having to punchTheClown in the meantime.

这篇关于Swift ARKit如何完全杀死ARSession?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆