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